False == (False in [False])

2015 年 10 月 16 日
 glasslion
大家觉得这个表达式的值是什么?
4400 次点击
所在节点    Python
14 条回复
nayihz
2015 年 10 月 16 日
False
hahastudio
2015 年 10 月 16 日
False in [False] => True
False == True => False
你要是挑个感觉会歧义的也行啊
aaronlam
2015 年 10 月 16 日
楼上正解
理解好运算优先级的话,这不是很容易得到答案吗?
imn1
2015 年 10 月 16 日
True == (False in [False],)
这个呢?
kendetrics
2015 年 10 月 16 日
@imn1 False != [False] => False not in [False], ,对吧?
Hello1995
2015 年 10 月 16 日
简单粗暴。过程正如 #2 所言。
hahastudio
2015 年 10 月 16 日
@imn1
True == tuple => False
你这也就骗骗连语法都不懂的= =
imn1
2015 年 10 月 16 日
@hahastudio
不是问你,问 LZ 的
gccplus
2015 年 10 月 17 日
True == (False in [False])
True

True == (False in [False],)
False

一个逗号就不一样拉~~
fourstring
2015 年 10 月 17 日
@hahastudio 就是说,在这种情境下, Python 不会像 if object 这样调用对象的__bool__()方法来返回一个 bool 值进行计算?
hahastudio
2015 年 10 月 17 日
@fourstring 你遇到的不是一个 object ,是一个表达式啊
siteshen
2015 年 10 月 17 日
@fourstring 另如果所有 a == b 都转换成 bool 类型再比较的话,那么 a == True 或者 a == False 就必然为真了。不是一个物种,你让 python 怎么自动转换。

() == [] => False
1 == 1.0 => True
True == 1 => True
False == 0 => False
complex(1,0) == True
fourstring
2015 年 10 月 17 日
@siteshen
@hahastudio
感谢,一时没想明白……
easyhappy
2015 年 10 月 19 日
False == False in [False]
>>>True

为什么是 True ?

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/228644

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX