• 逻辑运算符


    '''
    #逻辑运算符 not and or
    #逻辑运算符的优先级 not > and > or,若为同一优先级,则从左到右计算
    #not为一元运算符,and,or均为二元运算符。and两边的式子,同时为真,则为真,有一个为假,则为假
    #or运算符,表达式有一边为真则为真,否则为假
    print(3<4 and 5>2)#True
    print(3>4 and 5>2)#False
    print(3>4 or 5>2)#True
    print(3>4 or 5<2)#False
    print(3<4 or 5>2)#True
    print(3<4 and 5>2 or 3>4 or 5<2 and 3>4 and 5>2)#True
    # a or b,若a为非零,则返回x
    print(2 or 3)#2
    print(5 or 6)#5
    print(0 or 3)#3
    print(0 or 6)#6
    print(2 or 0)#2
    
    
    #如果为and,a and b,如果a为真,则返回b,即a为非零,则返回b,与or相反
    print(2 and 3)#3
    print(5 and 6)#6
    print(0 and 3)#0
    print(0 and 6)#0
    print(2 and 0)#0
    '
    '''
    
    
    #bool值为True,False
    print(bool(1))#True
    print(bool(0))#False  
    
    print(int(True))#1
    print(int(False))#0

    #逻辑运算符的计算
    print(2 or 1<3)#2
    #1<3为True,2 or True,2为非零,返回2
    print(2 or 1<3 and 2)#2
    #先计算and,1<3为True,True and 2,True 为真返回2,就变为2 or 2,结果就为2
    
    
    print(2 and 1<3)#True
    # 1<3 is True,so 2 and 1<3 is True,because 2 and True,2 is True,so return True
    print(2 and 1<3 and 2)#2
    #2 and 1<3  is True,so True and 2,because of Ture is True,return 2
     
  • 相关阅读:
    ceph集群jewel版本 rbd 块map 报错-故障排查
    基本的Ceph性能测试工具和方法
    dd命令的高级应用
    Ceph recover的速度控制
    Linux mount命令
    Centos7.2:搭建Ceph管理系统Inscope
    rpm --import /etc/pki/rpm-gpg/RPM* 有什么用?
    dd命令的解释
    Playbooks 中的错误处理
    Ansible之Playbooks的when语句
  • 原文地址:https://www.cnblogs.com/GZ1215-228513-Chichy/p/11235086.html
Copyright © 2020-2023  润新知