python逻辑运算符中not,and,or的优先级比较


 1 >>> a=3
 2 >>> b=4
 3 >>> c=5
 4 >>> d=6
 5 >>> c>d and b>a or d>c
 6 True
 7 ‘’‘>>> c>d and b>a not c>d
 8   File "<stdin>", line 1
 9     c>d and b>a not c>d
10                     ^
11 SyntaxError: invalid syntax’‘’
12 >>> c>d and b>a or  not c>d
13 True
14 >>> c>d and b>a or not d>c
15 False
16 >>>

由上所述,逻辑运算符中的优先级为not>and>or

不过一般写代码时最好不要这样写,尽量给代码加上括号,方便读者阅读


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM