Python has the following operators in total
Arithmetic operators
>>> a=9>>> b=2>>> a+b# add operation is 9+2=1111>>> A-b# The subtraction operation is 9-2=77>>> a*b# multiplication is 9*2=1818>>> A/b# divide operation is 9/2= 4.5, here is the PY3.5 version, the 2.7 version of the following only the integer part is 44.5>>> a//b# Floor Division, just take the integer part, do not 4>> after the decimal point > A**b# power operation, that is, 9 of the 2 is the Bayi81
2. Comparison operators
>>> a>=b#Check if a is greater than or equal to B, or true if yesTrue>>> a==b#Check if A is equal to B, if yes, true, otherwise falseFalse>>> a<=b#Check if a is less than or equal to B, or True if yes, false otherwiseFalse>>> a!=b#Check whether a is not equal to B, or true if yesTrue>>> a<>b#Check if a is not equal to B, if yes, true, here py3.5 version does not exist <>syntaxerror:invalid Syntax>>> a<>bsyntaxerror:invalid Syntax>>> a>b#Check if A is greater than B, if yes, trueTrue>>> a<b#Check if A is less than B, if yes, true, otherwise falseFalse
3. Assignment operators
>>> a=9>>> b=2>>> c=a+b#Assign the result of A+b to C>>>C11>>> a+=b#is a=a+b, assigning the result of A+b to a.>>>a11>>> a-=b#Assign the result of a-B to a>>>a9>>> a*=b#Assign the result of A*b to a>>>a18>>> a/=b#Assign the result of a/b to a>>>a9.0>>> a%=b#Assign the result of A%b to a>>>a1.0>>> a**=b#Assign the result of A**b to a>>>a1.0>>> a//=b>>>a0.0
4. Bitwise operators
If a = 60; and b = 13; binary Format bitwise operation:
A = 0011 1100
b = 0000 1101
-----------------
a&b = 0000 1100# and operation, if the same is 1 operation result is 1, otherwise 0
A|b = 0011 1101# or operation, if one is 1, the result of the operation is 1, otherwise 0
A^b = 0011 0001# xor operation, the corresponding two number is different 1, the same is 0
~a = 1100 0011# reverse operation, change the original 1 to 0, 0 for 1
5. Logical operators
And, or, not, and is two digits, two is true, and the result is true. Or it is true if one evaluates to True. Not is to take non-operation, the original result is true, take non-operation is false
>>> a=True>>> b=True>>> c=False>>>Print(A andb) True>>>Print(A andc) False>>>Print(Aorb) True>>>Print(Aorc) True>>>Print( not(A andb)) False>>>Print( not(A andc)) True
6. Member Operators
In, not in
>>> a="wsp">>> b="w"printin a)# to determine if the B character is inside a, if it istruetrueprint not in a)) # determine if the B character is not in a, if it is not true, it will be false False
7. Identity operator
is btrue is not bfalse>>> ID (a)39280952l>>> ID (b)39280952L
Determine if the memory address of A, B is the same as true, which is false
The Python operator