算数运算符 + - * / % // **
比较运算符 == , != , > , < , >=, <=
赋值运算符 = += -= *= /= %= **= //=
位运算 & | ^ - << >>
逻辑运算符 and or not
成员运算符 in ;not in
身份运算符 is; is not
对于逻辑运算符:a=10, b=20
python 中的 and 从左到右计算表达式,若所有值均为真,则返回最后一个值,若存在假,返回第一个假值;
or 也是从左到有计算表达式,返回第一个为真的值;
其中数字 0 是假,其他都是真;
字符 "" 是假,其他都是真;
image.png
a = 0
b = 10
a and b # 0
a = 3
a and b #10
a = False
a and b # False
b = 0
a and b #False
# =========================
a = 0
b = 10
a or b # 10
a = 1
a = True
a or b # 1
a or b # True
a = 0
b = False
a or b #False
image.png
a = 10
list = [1,2,4,5,10]
tuple = (1,2,3,10)
dict = {10: 20}
a in list
a in tuple
a in dict
结果都为True
image.png
网友评论