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

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


2、'and'运算符:

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

3、'or'运算符:

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

4、逻辑短路:

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

5、布尔值为假的十种情况:

1)、0
2)、0.0
3)、False
4)、""
5)、()
6)、[]
7)、set()
8)、{}
9)、0j
10)、None
原文地址:https://www.cnblogs.com/fengting0913/p/13252162.html