Go to: Na-Rae Han's home page  

Python 2.7 Tutorial

With Videos by mybringback.com

#19: Intro to Logic

                          << Previous Tutorial           Next Tutorial >>
On this page: Boolean type True, False. and, or, not.

Get Started

Video Summary

  • Shell session from this tutorial.
  • There are two logical values that Python recognizes: True and False. You can assign variables these logical values, such as x = True, and also use them in conjunction with each other with the operators and and or.
  • These operators have different functions: and requires all arguments within a statement to be true in order for Python to return a value of true, while or requires just one of the values to be true for Python to return a value of true. For example, the line True and False will return a value of false, while True or False will return a value of true. From more information on how Python comes to these answers, please refer to a formal logic truth table.
  • It is important to remember that and is a short circuit operator. This means that Python will only consider the second argument of statement using and if the first argument is true; if the first argument is false, Python will automatically return a value of false for the statement without considering or calculating the second argument at all.
  • Finally, Python also has a not operator. This simply reverses the truth value of the statement at hand, so that not True returns a value of False and not False returns a value of True.

Learn More

Explore