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