因為Python把0、空字符串''和None看成?False,其他數值和非空字符串都看成?True,所以:print 'hello,', a or 'world'的打印結果是a;hello,python。print 'hello,', b or 'world'的打印結果是:hello,world。
舉報
0/150
提交
取消
因為Python把0、空字符串''和None看成?False,其他數值和非空字符串都看成?True,所以:print 'hello,', a or 'world'的打印結果是a;hello,python。print 'hello,', b or 'world'的打印結果是:hello,world。
2014-10-23
舉報
2014-10-23
又涉及到 and 和 or 運算的一條重要法則:短路計算。