Python中的逻辑运算符:'and'与'or'的用法
2021-04-26 13:29
阅读:654
标签: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
上一篇:C++ 引用作为函数的返回值
下一篇:001 C++基础
文章来自:搜素材网的编程语言模块,转载请注明文章出处。
文章标题:Python中的逻辑运算符:'and'与'or'的用法
文章链接:http://soscw.com/index.php/essay/79811.html
文章标题:Python中的逻辑运算符:'and'与'or'的用法
文章链接:http://soscw.com/index.php/essay/79811.html
评论
亲,登录后才可以留言!