更多课程 选择中心


Python培训

400-111-8989

Python中布尔表达式练习

  • 发布:Python培训
  • 来源:花辞镜
  • 时间:2019-08-05 16:27

在 Python 中,用于存储真值和假值的类型称为 bool,以英国数学家 George Boole(乔治·布尔)的名字命名。George Boole 创建了布尔代数,它是所有现代计算机算术的基础。

布尔值只有两个,分别是 True 和 False。一定要注意大小写,因为 true 和 false 并不是布尔值(记住,Python 是区分大小写的)。

True Or False:

print(True and True,'\n',

False and True,'\n',

1 == 1 and 2 == 1,'\n',

"test" and "test",'\n',

1 == 1 or 2 != 1,'\n',

True and 1 == 1,'\n',

False and 0 != 0,'\n',

True or 1 == 1,'\n',

"test" == "testing",'\n',

1 != 0 and 2 == 1,'\n',

"test" != "testing",'\n',

"test" == 1,'\n',

ot (True and False),'\n',

ot (1 == 1 and 0 != 1),'\n',

ot (10 == 1 or 1000 == 1000),'\n',

ot (1 != 10 or 3 == 4),'\n',

ot ("testing" == "testing" and "Zed" == "Cool Guy"),'\n',

1 == 1 and not ("testing" == 1 or 1 == 0),'\n',

"chunky" == "bacon" and not (3 == 4 or 3 == 3),'\n',

3 == 3 and not ("testing" == "testing" or "Python" == "Fun"))

执行结果如下:

C:\wok\venv\Scripts\python.exe C:/wok/venv/ex28.py

True

False

False

test

True

True

False

True

False

False

True

False

True

False

False

False

True

True

False

False
Python中布尔表达式练习

免责声明:内容和图片源自网络,版权归原作者所有,如有侵犯您的原创版权请告知,我们将尽快删除相关内容。

预约申请免费试听课

填写下面表单即可预约申请免费试听! 怕学不会?助教全程陪读,随时解惑!担心就业?一地学习,可全国推荐就业!

上一篇:Python中的可变对象与不可变对象
下一篇:使用Python制作表白小程序

Python IDE推荐7个你可能会错过的Python IDE

Python面试题之Python中爬虫框架或模块的区别

2021年Python面试题及答案汇总详解

python数据分析,你需要这些工具

  • 扫码领取资料

    回复关键字:视频资料

    免费领取 达内课程视频学习资料

Copyright © 2023 Tedu.cn All Rights Reserved 京ICP备08000853号-56 京公网安备 11010802029508号 达内时代科技集团有限公司 版权所有

选择城市和中心
黑龙江省

吉林省

河北省

湖南省

贵州省

云南省

广西省

海南省