首页 > 编程语言 > 详细

python 布尔值 bool( ) 与逻辑运算符

时间:2018-06-10 13:57:16      阅读:264      评论:0      收藏:0      [点我收藏+]

逻辑运算符

not

and

or

运算符优先级

not > and >or

printer(x or y)  x为非零,则返回x,否则返回y

print(1 or 2)
print(3 or 2)
print(0 or 1)
print(0 or 3)

#打印结果
1
3
1
3

printer(x and y)  x为非零,则返回y,x为零,则返回x

printer(1 and 2)

printer(0 and 2)

printer(2 and 3)

#运行结果

2

0

3

数字转换布尔值

printer(bool(1))

printer(bool(0))

printer(bool(2))

#运行结果

True

False

True

 

python 布尔值 bool( ) 与逻辑运算符

原文:https://www.cnblogs.com/stationing/p/9162625.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!