布尔值的非和加法运算的评估
有人可以解释一下这两个代码片段中的操作顺序吗?我不明白为什么我得到不同的输出: True
在以下情况下:
print(not not True + True + False)
和 2
在以下情况下:
print((not not True) + True + False)
Can someone please explain the order of operations in these two code snippets? I don't understand why I get different outputs: True
in the case of:
print(not not True + True + False)
and 2
in the case of:
print((not not True) + True + False)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用此表作为运算符优先级,我们看到
+
的优先级高于not
。因此:相当于 相当于
相当于 相当于
相当于
相当于
我们可以对第二次打印遵循类似的过程:
相当于:
通过布尔加法,结果为:
Using this table for operator precedence, we see that
+
has a higher precedence thannot
. So:is equivalent to
which is equivalent to
which is equivalent to
which is equivalent to
We can follow a similar procedure for the second print:
is equivalent to:
which, by boolean addition, results in: