https://www.cnblogs.com/xuexianqi/p/12425769.html

逻辑运算符用于连接多个条件,进行关联判断,会返回布尔值True或False

1.not

逻辑 非,也就是取反

偷懒原则:not 就是:真变假,假变真

print(not 1) #1在逻辑运算中代表True,not 1 就是 not True
False

print(not 0) #1在逻辑运算中代表False,not 0 就是 not False
True

2.and

逻辑 与

偷懒原则:and 就是:全真为真,一假即假

print(1 and 4>1 and True)
True

print(3>4 and 0 and False and 1)
False

3.or

逻辑 或

偷懒原则:or 就是:一真即真,全假为假

print(1 or 4>1 or True)
1 #1在逻辑运算中代表True

print(3>4 or 0 or False)
False

二:优先级

not > and > or

PS:如果单独就只是一串and连接,或者单独就只是一串or连接,按照从左到右的顺序运算

PS:如果是混用,则需要考虑优先级了

()拥有最高优先级,“()”内的内容直接提升到第一优先级,先运算

相关文章:

  • 2021-04-29
  • 2021-09-02
猜你喜欢
  • 2021-11-19
  • 2021-11-19
  • 2021-12-02
  • 2021-07-31
  • 2021-11-14
  • 2022-01-22
  • 2022-12-23
相关资源
相似解决方案