首页 > 编程语言 > 详细

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

时间:2020-02-09 17:12:38      阅读:112      评论:0      收藏:0      [点我收藏+]
 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

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

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

原文:https://www.cnblogs.com/Crystal0717/p/12287559.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!