1.算数运算符 +,-,*,/,%,**,//
(1)加号(Plus) +
(2)减号(Minus)-
(3)乘号(Multipy) *
(4)乘方(Power)**
例如:3 ** 4 = 3 * 3 * 3* 3
(5)除号1(Divide) /
(6)除号2(Fllor) //
a // b:结果与a,b的小数位有关
(7) 模(Modulo)%
2.位操作运算符
(1)左移位(Left Shift)<<
2 << 2 -->00000010向左移动2位:00001000 = 8(等效于右边加2个0,左边去2个0)
(2)右移位(Right Shift)>>
与左移位相反
(3)按位与(Bitwise AND)&
5 & 3 = 00000101 & 00000011 = 00000001(都是1才为1,否则为0)
(4)按位或(Bitwise OR)|
5 | 3 = 00000101 | 00000011 = 00000111(有1为1,都是0才为0)
(5)按位异或(Bit-wise XOR) ^
5 ^ 3 = 00000101 ^ 00000011 = 0000110(都是1或都是0返回0,否则返回1)
(6)按位取反(Bit-wise invert) ~
~ x = - (x+1)
例如:~00000101 = - 00000110 = 10000110
3.比较运算符 >, <, >=, <=, !=, ==,返回值是True,False
(1)小于(Less Than)<
(2)小于等于(Less Than or Equal To)<=
(3)大于(Greater Than)>
(4)大于等于(Greater Than or Equal To)>=
(5)判断是否等于(Equal To)==
(6)不等于(Not Equal To)!=
4.逻辑运算符 and, or, not,返回值是True,False
(1)布尔否(Boolean NOT)not
(2)布尔与(Boolean AND)and
都为True才返回True,否则返回False
(3)布尔或(Blooean OR)or
5.成员运算符 in, not in ,返回值是True,False
s = 'hello' print('o' in s) print('o' not in s) l = [1, 2, 3] print(3 in l) n = {"age":18, "name":"kite"} print(18 in n) # False print('age' in n) # True # 主要判断key