Boolean Expressions

Boolean Expressions

  • x and y
  • x or y
  • not x

Short-circuit behavior

  • x and y only evaluates y if x is true.
  • x or y only evaluates y if x is false.

Truth values

  • Non-zero values and non-empty objects evaluate as true.
  • None and zero-length strings, lists, tuples, and dictionaries evaluate as false.
<<< O'Reilly OSCON 2000, Introduction to Python, Slide 61
July 17, 2000, beazley@cs.uchicago.edu
>>>