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
相关文章
相关标签/搜索