基本运算符
算术运算符
+ - * / % // **
返回一个数值
比较运算符
> >= < <= == != <>
返回布尔值
赋值运算符
= -= += *= /= %= //= **=
例:
x += 1 # 等同于 x = x + 1
x %= 2 # 等同于 x = x % 2
逻辑运算符
and 两边条件同时为True,则为True
or 两边条件只要有一个为True,就为True
not 若条件为True,则not后为False,若条件为False,则not后为True
身份运算符
is 比较变量的内存地址
print(x is y)
# 等同于
print(id(x) == id(y))
位运算符
按位运算符是把数字看作二进制来进行计算的

成员运算符
in 判断成员是否在容器里面
class = ['Chinese','Math','English']
print('Chinese' in class) # True
print('science' not in class) # True
# not in 也可以为:
print(not 'Math' in class) # False

浙公网安备 33010602011771号