和在python中代表什么
我在python控制台中尝试了一些示例。并对以下几点感到困惑:和在python中代表什么,python,Python,我在python控制台中尝试了一些示例。并对以下几点感到困惑: >>> (1 and None) >>> (1 and None) == None True >>> (1 or None) == None False >>> (1 and 2) == 2 True >>> (2 and 1) == 2 False >>> (2 and 1) == 1 True 我很困惑,为什么(1和无)
>>> (1 and None)
>>> (1 and None) == None
True
>>> (1 or None) == None
False
>>> (1 and 2) == 2
True
>>> (2 and 1) == 2
False
>>> (2 and 1) == 1
True
我很困惑,为什么(1和无)不返回任何东西是第1行?应该没有?为什么(2和1)等于1而不是2。很抱歉,Python出现了新问题。在Python中,
空字符串、dict、元组、list为False。
其他的都是真的
(1和无)
与相同,如果1为假,则返回1,否则无
这就是为什么(1和None)返回None
同样的原因==>(2和1)返回1,所以它不是2
我的英语不好,你可以从下面的链接找到更多信息
尝试打印(1和无)。除非明确要求打印,否则Shell不会打印
None
。有关未显示None
的原因:请参阅文档:(4.1和4.2)@JRodDynamite,它不会打印任何内容!但是为什么1和2会打印2,我认为应该是返回0的1和2….1和2
与1和2
不同。