字符串的一個疑團:
爲什麼bool('foo')
返回True
?
神祕案件,和對象標識符
如果
'foo' == True
回報False
'foo' == False
回報False
'foo' is True
回報False
'foo' is False
返回False
整數的第二個祕密:
bool(5)
怎麼回來True
?
如果
5 == True
回報False
5 == False
回報False
5 is True
回報False
5 is False
回報False
零的第三個謎:
怎麼來bool(0)
返回False
?
如果
0 == True
返回False
0 == False
回報True
< - 特例
0 is True
返回False
0 is False
回報False
我意識到Python的一些真實性,但是,這一切似乎有點神祕。有人介意在這方面解釋一些情況嗎?
[真值測試](https://docs.python.org/2/library/stdtypes.html#truth-value-testing) –