记住逻辑关系
逻辑术语
在 python 中我们会用到下面的术语(字符或者词汇)来定义事物的真(True)或者假(False)。计算机的逻辑就是在程序的某个位置检查这些字符或者变量组合在一起表达的结果是真是假。
• and 与
• or 或
• not 非
• != (not equal) 不等于
• == (equal) 等于
• >= (greater-than-equal) 大于等于
• <= (less-than-equal) 小于等于
• True 真
• False 假
其实你已经见过这些字符了,但这些词汇你可能还没见过。这些词汇(and, or, not)和你期望的效果其实是一样的,跟英语里的意思一模一样。
真值表
我们将使用这些字符来创建你需要记住的真值表。
NOT | True? | 备注 |
not False | True | 不是假的=真的 |
not True | False | 不是真的=假的 |
OR | True? | 备注 |
True or False | True | 有一个为真的=真 |
True or True | True | |
False or True | True | |
False or False | False | |
AND | True? | 备注 |
True and False | False | 两个都为真=真 |
True and True | True | |
False and True | False | |
False and False | False | |
NOT OR | True? | 备注 |
not(True or False) | False | 不是(真)=假 |
not(True or True) | False | |
not(False or True) | False | |
not(False or False) | True | 不是(假)=真 |
NOT AND | True? | 备注 |
not(True and False) | True | 不是(假)=真 |
not(True and True) | False | 不是(真)=假 |
not(False and True) | True | |
not(False and False) | True | |
!= | True? | 备注 |
1 != 0 | True | |
1 != 1 | False | |
0 != 1 | True | |
0 != 0 | False | |
== | True? | 备注 |
1 == 0 | False | |
1 == 1 | True | |
0 == 1 | False | |
0 == 0 | True |