zoukankan      html  css  js  c++  java
  • Python--Demo5--布尔类型相关操作

    布尔类型:

    我们已经知道布尔类型只有两个值True和False

    布尔类型的操作:

    比较运算、逻辑运算;操作结果都是布尔值。

    比较运算符:

    完成比较运算需要知道,比较运算符。(== 等于)(!= 不等于)(> 大于) (<小于)(<= 小于等于)(>= 大于等于)

    示例:

    >>> 33.0==33
    True
    >>> 'hehe'=='hehe'
    True
    >>> 'HeHe'=='hehe'
    False
    >>> 3!=3
    False
    >>> 3==3
    True
    >>> 3>2
    True
    >>> 3=='3'
    False
    >>> 'a'>1
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    TypeError: '>' not supported between instances of 'str' and 'int'

    说明:>、<、>=、<= 只能用于整型和浮点型之间

    布尔操作符:

    布尔操作符是两个布尔值之间的运算,布尔操作符有 and  or  not

    示例:

    >>> True and False
    False
    >>> True or False
    True
    >>> not True
    False
    >>> (1==1) and (1>=2)
    False
    >>> (1==1) or (1>=2)
    True
    >>> 2+2 == 4 and not 2+2==5 and 2*2 ==2+2
    True
    >>> "bobo" and False
    False

    说明:布尔操作符优先级 not最高、其次时and 和or

  • 相关阅读:
    什么是web标准、可用性、可访问性
    前端面试>逻辑推理题~~
    git 安装
    wcf生成客户端代理的四种方法
    mysql 安装
    理解Linux 的处理器负载均值load averages
    高性能服务器架构
    事务日志
    Epoll工作模式详解
    事务和两阶段提交
  • 原文地址:https://www.cnblogs.com/bigbosscyb/p/12318351.html
Copyright © 2011-2022 走看看