运算符
算数运算符
赋值运算符
# 单变量赋值
num=1
# 多变量赋值
num1, float1, str1 = 10, 0.5, 'hello world'
# 多变量赋相同值
a = b = 10
复合赋值运算符
c=10
c+=1+2
# 13 先算运算符右侧1 + 2 = 3, c += 3 , 推导出c = 10 + 3
比较运算符
也叫关系运算符。
逻辑运算符
a = 0
b = 1
c = 2
print((a < b) and (b < c)) # True
print((a > b) and (b < c)) # False
print((a > b) or (b < c)) # True
print(not (a > b)) # True
# 数字之间的逻辑运算
# and运算符 只有有一个值为0,则结果为0,否则结果为最后一个非0数字
print(a and b) # 0
print(a and c) # 0
print(b and c) # 2
print(c and b) # 1
# or运算符 只有所有值为0,结果才为0,否则结果为第一个非0数字
print(a or a) # 0
print(a or c) # 2
print(c or a) # 2
print(b or c) # 1