或運算假假輸出后一個假吧?
a = 'python'? ? ? ? ? ? ? ? ? ? ? ? ? ? #a為真True
print 'hello,', a or 'world'? ? ? ? #a為真,或運算world為假得出結果python(或運算中一方為真即為真)
#輸出結果為:hello, python
b = ''? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?#空字串符默認為False假
print 'hello,', b or 'world'? ? ? ? ? #b為假,或運算world為假,得出結果world(或運算假假得最后一個假)
#輸出結果為:hello, world
請問老師,我這么理解對嗎?還有第二個world我理解為假,對嗎?
2019-10-23
‘world'應該為真吧?對嗎?
print’hello‘,’world‘ or a
#輸出結果為:hello,world ? 那說明world為真直接輸出
是這樣理解嗎??
2019-10-02
根據短路運算:
a = 'python'? ? ? ? ? ? ? ? ? ? ? ? ? ? #a為真True
print 'hello,', a or 'world'? ? ? ? #a為真,就不管后面是真假了,直接輸出a,即python(或運算中一方為真即為真)
#輸出結果為:hello, python
b = ''? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?#空字串符默認為False假
print 'hello,', b or 'world'? ? ? ? ? #b為假,不管后面是真是假,直接輸出后面的結果world(或運算假假得最后一個假)
#輸出結果為:hello, world
總結:短路運算就是先判斷前一個為真假,在此基礎上,直接得出結果。后面的不再進行判斷。