设为首页 加入收藏

TOP

Python中的not, and, or
2018-11-14 22:08:19 】 浏览:76
Tags:Python not and

Python中的逻辑运算符

  not, and, or

and 与运算

  两者为真则为真

  >>>True and True

  True

  其中一个为假,则为假

  >>>True and False

  False

or 或运算

  两者为假则为假

  >>>False or False

  False

  其中一个为真,则为真

  >>>False or True

  True

not 非运算

  颠倒布尔值的结果(PS: True 和 False 都为布尔值(Booleans))

  >>>not True

  False

逻辑运算符的优先级

  not > and > or

  (PS: 同等优先级从左往右进行运算)

 

实例

  >>>not False or True and False

  解析

    先处理not False --> True

    >>>True or True and False

    再处理 True and False -->False

    >>>True or False

    True

 

练习

  >>>b_1 = True or False or True

  >>>b_2 = True and not False

  >>>b_3 = False and True or not True

 

>>>b_1

True

>>>b_2

True

>>>b_3

False

 

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇python学习之旅(四) 下一篇Python记录_day21 模块

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目