python逻辑运算之and、or

    • 逻辑运算符

      • and or not

      • 在没有()的时候 优先级 not>and>or

      • 两边都是比较运算的时候,同一优先级 从左至右

        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

猜你喜欢

转载自www.cnblogs.com/he-qing-qing/p/11297913.html