Python中的逻辑运算题,一起来分析一下吧
在Python中请用最快速度说出答案:not 1 or 0 and 1 or 3 and 4 or 5 and 6 or 7 and 8 and 9
答案是:4
对于这道题,我是这样分析的不知道对不对。参考了PHP和js的理解,希望大家看看有没有什么问题,希望给我指正一下。感谢您们的帮助。
首先,我人为的加上圆括号帮助分析:(not 1) or (0 and 1) or (3 and 4) or (5 and 6) or ((7 and 8) and 9),
其次,我的理解是:逻辑运算符,首先优先级,not>and>or。其次,x or y 如果x为:true的值,则返回x的值,否则返回y值。 x and y 如果x为false,则返回x的值,否则返回y值。
再次感谢大家 (not 1) or (0 and 1) or (3 and 4) or (5 and 6) or ((7 and 8) and 9)
== 0 or 0 or 4 or 6 or 9
== 0 or 4 or 6 or 9
== 4 or 6 or 9
== 4 or 9
== 4 zltzlt 发表于 2019-10-7 11:49
(not 1) or (0 and 1) or (3 and 4) or (5 and 6) or ((7 and 8) and 9)
== 0 or 0 or 4 or 6 or 9
...
感谢您的分析,非常感谢。明白了,和我思考的一样。谢谢
页:
[1]