大家觉得这个表达式的值是什么?
1
nayihz Oct 16, 2015
False
|
2
hahastudio Oct 16, 2015
False in [False] => True
False == True => False 你要是挑个感觉会歧义的也行啊 |
3
aaronlam Oct 16, 2015
楼上正解
理解好运算优先级的话,这不是很容易得到答案吗? |
4
imn1 Oct 16, 2015
True == (False in [False],)
这个呢? |
5
kendetrics Oct 16, 2015
@imn1 False != [False] => False not in [False], ,对吧?
|
6
Hello1995 Oct 16, 2015
|
7
hahastudio Oct 16, 2015
|
8
imn1 Oct 16, 2015
@hahastudio
不是问你,问 LZ 的 |
9
gccplus Oct 17, 2015
True == (False in [False])
True True == (False in [False],) False 一个逗号就不一样拉~~ |
10
fourstring Oct 17, 2015
@hahastudio 就是说,在这种情境下, Python 不会像 if object 这样调用对象的__bool__()方法来返回一个 bool 值进行计算?
|
11
hahastudio Oct 17, 2015
@fourstring 你遇到的不是一个 object ,是一个表达式啊
|
12
siteshen Oct 17, 2015
@fourstring 另如果所有 a == b 都转换成 bool 类型再比较的话,那么 a == True 或者 a == False 就必然为真了。不是一个物种,你让 python 怎么自动转换。
() == [] => False 1 == 1.0 => True True == 1 => True False == 0 => False complex(1,0) == True |
13
fourstring Oct 17, 2015
|
14
easyhappy Oct 19, 2015
False == False in [False]
>>>True 为什么是 True ? |