Python simplified introductory data types– variable

* What are the variables?

+ you can think of the variable ratio as a box of things, depending on what you want to put in it, when you put in an apple it’s an apple, and when you put in a pear it’s a pear.

+ definition: A variable is a contiguous storage space with a name. We can apply for and name such storage space by defining a variable and use the name of the variable.

+ syntax structure: variable name = stored data (assign data to variable name)

+ variable can be assigned multiple times [the amount of value that can change during program execution]

  • Naming rules for variables:

+ variables must begin with a header (A-z, a-z) or an underscore (_)

+ Other characters can be letters, numbers, or underscores

+ variables are case-sensitive

+Python keywords cannot be used as variable names

The variable name cannot start with a number

Print (Name, Name) _age = 50 print(Name, Name) _age = 50 print(Name, Name) _age = 50 print(Name, Name) _age = 50 Print (Name,_age) user_name = 'CCCP' user_age = 20Copy the code

– Data type

# # - int (integer) - long (long) (python3 cancelled) # - float (float type) # Numbers (num) - complex (plural) # # # -- -- -- True - Boolean value (bool) - # Python basic data types -- --False # # string # dict # Tuple # listCopy the code
Print (type(a)) b = 12.3 # print(type(b)) c = True # print(type(b) Print (type(c)) d = () # tuple type print(type(d)) e = [] # print(type(e)) f = {} # Before you can use itCopy the code

– Arithmetic operator

* + - * / % ** // arithmetic operatorCopy the code
A = 7 b = 3 c = 10 print(a+b) print(a*b) print(a/b) print(a%b) print(a**b) print(a/b) print(a%b  print(a+b*c)Copy the code

– Comparison operator

  • = =! = > < >= <= (Equal to, not equal to, greater than, less than, greater than or equal to, less than or equal to)
Print (a==b) print(a! =b) print(a>b) print(a<b) print(a>=b) print(a<=b)Copy the code

– Logical operator

*and
Copy the code
Print (a+b>c and c<d) # False print(c>d and a>b)Copy the code
The result is true if one of the or conditions is trueCopy the code
Print (a<b or b>d) # True print(a<b or b<d) # FalseCopy the code
* not take backCopy the code
print(not a<b)
print(not a>b)
Copy the code
* Priority +()-->not-->and--> ORCopy the code
print(2>1 and 1<4 or 2<3 and 9>6 or 2<4 and 3<2)
Copy the code

– Assignment operator

* +=  -=  *=  /=  %=  **=
Copy the code
A, b, c, d = 23,18,10,3Copy the code
* a + a = a + c = c in the same wayCopy the code
a**=2
print(a)
Copy the code

– Input and output

* placeholder %Copy the code
Name = 'my' classPro = 'UESTC class 2' age = 16 print('%s' Print ('%s ') print('%s ') print('%s ') print('%s ') print('%s ') Print (' format(name,classPro,age) ')Copy the code
* Data input input()Copy the code
Name = input (' name:) age = int (input (' age:)) qq = input (' qq:) phone = input (' phone: ') addr = input (' address: ') print (' name: % s Age is: % d '% (name, age)) print (" name: age is: {} {} ". The format (name, 25)) print (' QQ: {}'. The format (QQ) print (' telephone: {} '. The format (phone)) Print (' address: {} '. The format (addr))Copy the code
'% type '+%+ placeholder data name '{}'+.format(placeholder data name)Copy the code