运算符
Last updated
Last updated
运算符 描述
** 指数 (最高优先级)
~ + - 按位翻转, 一元加号和减号 (最后两个的方法名为 +@ 和 -@)
* / % // 乘,除,取模和取整除
+ - 加法减法
>> << 右移,左移运算符
& 位 'AND'
^ | 位运算符
<= < > >= 比较运算符
<> == != 等于运算符
= %= /= //= -= += *= **= 赋值运算符
is is not 身份运算符
in not in 成员运算符
not or and 逻辑运算符''' x or y x Ture, return x '''
print(1 or 2) # 1
print(3 or 2) # 3
print(0 or 2) # 2
print(0 or 100) # 100
''' x and y x true,return y '''
print(1 and 2) # 2
print(0 and 2) # 0
print(0 or 4 and 3 or 2) # 优先级 4 and 3, 0 or 3 or 2 => 2
print(1 > 2 and 3 or 4 and 3 < 2) # False
print(2 or 1 < 3 and 2) # 2