Truth Tables Python
Today is the day you start learning about logic. Up to this point, you have done everything you possibly can, reading and writing files to the Terminal, and have learned quite a lot of the math capabilities of Python.
From now on, you will be learning logic. You won’t learn complex theories that academics love to study but just the simple basic logic that makes real programs work and that real programmers need every day.
Learning logic has to come after you do some memorization. I want you to do this exercise for an entire week. Do not falter. Even if you are bored out of your mind, keep doing it. This exercise has a set of logic tables you must memorize to make it easier for you to do the later exercises.
In Python we have the following terms (characters and phrases) for determining if something is “True” or “False.” Logic on a computer is all about seeing if some combination of these characters and some variables is True at that point in the program.
- not != (not equal)
- == (equal)
- >= (greater- than- equal)
- <= (less- than- equal)
You actually have run into these characters before, but maybe not the phrases. The phrases (and, or, not) actually work the way you expect them to, just like in English.
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
Can’t I just learn the concepts behind boolean algebra and not memorize this?
Sure, you can do that, but then you’ll have to constantly go through the rules to boolean algebra while you code. If you memorize these fi rst, it not only builds your memorization skills but also makes these operations natural. After that, the concept of boolean algebra is easy. But do whatever works for you