A variable is an area of computer memory in which variables can store values within a specified range, and values can be changed. The python under variable is the name of a reference variable to a data-the variable name consists of a letter, a number, and an underscore. -variables cannot start with a number-you cannot use the keyword-a a1 _a variable assignment-is the process of declaring and defining variables a = 1id (a) operator and expression Python operators include-assignment operators-arithmetic operators-relational operators-logical operator expressions are different data (including variables, function) A formula that is connected by a certain rule with an operation symbol.x = 2type (x)Show intx = ' 2 ' type (x) display str x = 2x +=2x display 4 x-=3x display 1 x *=4x display 4 x/=4x show 1 3 + 4 show 7 ' A ' + ' B ' Display ' AB ' 3-4 Display-1 3 * 4 display 12 4/ 3 Display 1 4.0/3 display 1.33333333333 4.0//3 Display 1.0 = Division of the portion 4//3 display 1 4% 3 2**3 Display 8 2 of the 3-2**10 display 1024 2 of 10-side 1 > 2 display FAL SE 1 < 2 display true 1 >= 2 display false 1 = = 1 Display true 1== 2 display false 1! = 2 Display True logical operator and logical with: true and Falseor logic or: false or Truenot logical non: Not true1 = = 2 and 2 > 1Show False1 = = 1 and 2 > 1Display True1 = = 2 or 2 > 1 show true not 1 = = 2 Display true write a arithmetic-requires reading from the keyboard the number input () and raw_input () difference input ("please input:") enter 123, display 123 output Enter ' ABC ' display ' ABC ' Input ABC will errorraw_input ("Please input:")input ABCDJF, display ' ABCDJF 'Input 234 show ' 234 'Vim 3.py #!/usr/bin/python num1 = input ("a number:") num2 = input ("Please a number:") print "%s +%s =%s"% (NUM1, NUM2,NUM1+NUM2) print "%s-%s =%s"% (num1,num2,num1-num2) print "%s *%s =%s"% (num1,num2,num1*num2) print "%s/%s =%s" % (num1,num2,num1/num2) display: Python 3.pyPlease a number:4please a number:54 + 5 = 94-5 = 14 * 5 = 204/5 = 0 Simple Calculator[email protected] day01]# cat cal.py#!/usr/bin/python def counter ():While True:num1 = Int (raw_input ("Please input NUM1:"))oper = raw_input ("Please input oper:")num2 = Int (raw_input ("Please input num2:")) if Oper = = "+":print "%s +%s =%s"% (num1,num2, (num1+num2))elif oper = = "-":print "%s-%s =%s"% (num1,num2, (num1-num2))elif oper = = "*":print "%s *%s =%s"% (num1,num2, (num1*num2))elif oper = = "/":if num2 = = 0:print ' Error/zero ' BreakElse:print "%s/%s =%s"% (num1,num2, (float (NUM1)/float (num2)))exit = raw_input ("Input Q exit:")if exit.upper () = = "Q":Break ; counter ()
Variables for Python