0 and 'a' or 'b'逻辑运算符

巧妙的运用逻辑运算符来实现一个开关的功能
and : 为一假,则假
or : 为一真则真

 根据逻辑运算符的优先级:
 Lambda  #运算优先级最低
逻辑运算符: or
逻辑运算符: and
逻辑运算符:not
成员测试: in, not in
同一性测试: is, is not
比较: <,<=,>,>=,!=,==
按位或: |
按位异或: ^
按位与: &
移位: << ,>>
加法与减法: + ,-
乘法、除法与取余: *, / ,%
正负号: +x,-x

0 and ‘a’ or ‘b’
当为0时,0 and ‘a’为 0; 0 or ‘b’为b.
‘b’
1 and ‘a’ or ‘b’
当为1时,1 and ‘a’为 ‘a’; ‘a’ or ‘b’为’a’.
‘a’

猜你喜欢

转载自blog.csdn.net/weixin_42103706/article/details/81487389