The operator

Arithmetic operator

Print (1 + 1) print(1 + 1) 2 print(1-1); 0 print(1 * 2); 2 print(5/2); 2.5 print(5 // 2); 2 print(5%2) Print (1 ** 2); Print (-1 // 2) print(-1 // 2) print(-1 // 2) print(-1 // 2) print(-1 // 2) print(-1 // 2) print(-1 // 2) print(-1 // 2) print(-1 // 2) print(-1 // 2) print(-1 // 2) Print (1) print(2); Print (-1 // -1) print(-1 // -1) print(-1 // -1) print(-1 // -1) Print (% 2) print(% 2) print(% 2) print(% 2) print(% 2) [(-1)-(2)*(-1)=(-1)+6=1] print(2) [5-(-1)*(-1)=5-6=-1] print(-1) They're both positive or negative, and the remainder is minus 1Copy the code

The assignment operator

A2 = b2 = c2 = 20 print(a2, id(a2)) print(b2, id(b2)) print(c2, id(b2)) Print (parm) parm -= 20 print(parm) parm *= 30 print(parm) parm /= 10 print(parm) # Print (x, y, z) print(x, y, z) print(x, y, z) print(x, y, z) Print (', temp1, temp2 ', temp1, temp2)Copy the code

Comparison operator

a, b = 10, 20 print(a > b) print(a < b) print(a <= b) print(a >= b) print(a == b) print(a ! Print (a == b) # True; print(a == b) # True; print(a == b) # True; Print (a is b) # True; Print (a is not b) # False; Print (list1 == list2) # True; print(list1 == list2) # True; print(list1 == list2) # True; Print (list1 is list2) # False; Print (list1 is not list2) # True; Identification inequalityCopy the code

Boolean operator

a, b = 1, 2 print(a == 1 and b == 2) # True print(a == 1 and b ! = 2) # False print(a ! = 1 and b == 2) # False print(a ! = 1 and b ! = 2) # False print(a == 1 or b == 2) # True print(a == 1 or b ! = 2) # True print(a ! = 1 or b == 2) # True print(a ! = 1 or b ! = 2) # False print(not True) # False print(not False) # True str_content = '123456' print('1' in str_content) # True print('9' in str_content) # False print('1' not in str_content) # False print('9' not in str_content) # TrueCopy the code

An operator

# bitwise and; Print (4 & 8) # 0; print(4 & 8) # 0; With 0 means that the result is 0 print (4 | 8) # 12 # left shift; Print (4 << 1) print(4 << 2) print(4 << 2) Print (4 >> 1) # 2 print(4 >> 2) # 1Copy the code