python邏輯運算之and、or

    • 邏輯運算符python

      • and or notcode

      • 在沒有()的時候 優先級 not>and>orclass

      • 兩邊都是比較運算的時候,同一優先級 從左至右co

        print(2>1and 3<4 or 4>5 and 2<1)
        
        x or y #x,y爲數字時候:x:非0則爲x,x:爲0則爲y
        # 非零即True  0 爲 Falese
        and 跟 or 相反
        or: 前面非0就打印前面的。
        and:前面爲0就是0,前面非0就是後面的。
        #例子
        print(1 and 2 or -1 and 3)
        #print(2 or 3)
        #打印結果2
相關文章
相關標籤/搜索