-2
我在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和None)不返回任何東西是行1?它應該是無?爲什麼(2和1)等於1但不是2。
試試'print(1 and None)'。除非明確告知打印,否則Shell不打印'None'。 – JRodDynamite
爲什麼'None'不顯示:http://stackoverflow.com/questions/39639342/none-is-not-displayed-as-i-expected-in-python-interactive-mode –
請參閱文檔:https: //docs.python.org/3/library/stdtypes.html#truth-value-testing(4.1和4.2) –