码迷,mamicode.com
首页 > 编程语言 > 详细

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

时间:2020-07-05 23:07:45      阅读:113      评论:0      收藏:0      [点我收藏+]

标签:strong   pytho   one   not   情况   优先级   表达式   als   lang   

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

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

标签:strong   pytho   one   not   情况   优先级   表达式   als   lang   

原文地址:https://www.cnblogs.com/fengting0913/p/13252162.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!