今天我们学校逻辑关系,前面我们已经学习了读取和写入文件,数学运算等。
我们不学习复杂的逻辑运行,只学一些基本的,平时经常用到逻辑关系。
学习逻辑之前你要做一些记忆,我希望你花一个星期完成。即使感到烦躁也不要放弃,坚持下去,这个联系需要记住一个逻辑关系表,对下面的章节会非常有用。
我必须警告,这个过程不是很好玩,将会非常的无聊和沉闷,不过这是程序员要掌握的重要技能。在生活中也要记住一些重要概念,等到用到的时候会相当激动。付出总会得到回报的。
记忆有一个小窍门:会比较短的时间记住一小部分重点,而不是花两个小时记住整个表格。你的大脑只会在开始的15-30分钟有效率的工作。
你可以做一些卡片,一面写这个答案,一面写这个问题,然后反复记忆和练习,直到你看到问题就能马上想到答案。
一旦你能做好这一点了,那么在笔记本上默写整个表格。
不要花超过一周的时间做这个练习,因为我们会在后面的练习中不断使用它。
真值术语
在python中,我们使用下面的术语去判断一个东西的True和False,计算机的逻辑判断就是当某些字符和变量组合在一起的时候是True还是False。
- and
- or
- not
- !=
- ==
- >=
- <=
- 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 |
花时间记住这些表格吧。