算术运算符
a=10,b=20
num1 = 10 num2 = 3 print(num1+num2) #13 print(num1-num2) #7 print(num1*num2) #20 print(num1/num2) #3.333333 print(num1%num2) #1 print(num1//num2) #3 print(num1**num2) #100
赋值运算符
比较运算符
a=10,b=20
a = 10;b = 5 print(a == b) # False print(a != b) # True print(a > b) # True print(a < b) # False
逻辑运算符
a = 10 b = 5 print(a>b and a<b) #False 两个条件为真 则为真 否则返回假 print(a>b or a<b ) #True 两个条件有一个为真则返回真, print( not a>b) #False
布尔测试
str = '' #空字符串 返回 bool false str = [] #孔的列表 返回 bool false str = () #空的元组 返回 bool false str = {} #空的字典返回 bool false num = 0 #0 返回 bool false print(bool(num))
位运算符
a=60,b=13
a = 4 b = 2 print(a & b) #输出0 print(a | b) #输出6 print(a ^ b) #输出6 print(~a) #输出-5(-4-1 = -5) ~运算:取反减一