truthy and falsey: python edition

2020-06-05

 | 

~1 min read

 | 

159 words

Just like Javascript, in Python, not everything’s black and white. Here too there are truthy things and falsey values.

Also, like Javascript, falsey is the more limited set. In fact, in Python, where everything is an object, is considered true by default. From the docs:

By default, an object is considered true unless its class defines either a bool() method that returns False or a len() method that returns zero, when called with the object. Here are most of the built-in objects considered false:

Estefania Cassingena Navone, in her Introduction to Truthy and Falsey Values in Python, separates the falsey values into three groups: Sequences and Collections, Numbers, and Constants:

Sequences and Collections:

  • Empty lists []
  • Empty tuples ()
  • Empty dictionaries {}
  • Empty sets set()
  • Empty strings ""
  • Empty ranges range(0) Numbers
  • Zero of any numeric type.
  • Integer: 0
  • Float: 0.0
  • Complex: 0j Constants
  • None
  • False


Hi there and thanks for reading! My name's Stephen. I live in Chicago with my wife, Kate, and dog, Finn. Want more? See about and get in touch!