Python中的逻辑运算符:'and'与'or'的用法

一、运算的优先级为:() > not > and > or;python


二、'and'运算符:code

  • 当两边都为真时才是真,且返回'and'后边的内容,
  • 当两边都为假时返回'and'前面的内容,
  • 当一真一假时返回表明假的内容;

三、'or'运算符:class

  • 当有一个为真时便是真,且返回表明真的内容,
  • 当两边都为假时返回'or'后面的内容,
  • 当两边都为真时返回'or'前面的内容;

四、逻辑短路:co

  • 1)、True or 表达式
  • 2)、False and 表达式

五、布尔值为假的十种状况:运算符

1)、0
2)、0.0
3)、False
4)、""
5)、()
6)、[]
7)、set()
8)、{}
9)、0j
10)、None
相关文章
相关标签/搜索