【发布时间】:2020-09-30 00:15:05
【问题描述】:
如果我有a = [1,2,3] 之类的东西,并且我写了1 in a == True 之类的语句,那似乎评估为假。
但是,如果我写 (1 in a) == True,则结果为 true。
我对 Python 如何评估第一条语句最终达到 false 感到有些困惑。
【问题讨论】:
-
为什么要打扰
== True?我认为像if 1 in a:这样的东西无论如何读起来更好。 -
1 in a == True表示1 in a and a==True。搜索 python 运算符链接 -
看完documentation之后有什么不明白的地方?我们希望您在帖子中包含该发现。
标签: python conditional-statements operator-precedence