What is Truthy and Falsy? How is it different from True and False?

All values are considered “truthy” except for the following, which are “falsy”:

  • None
  • False
  • Zeros, including:
  • Empty sequences and collections, including:
    • [] – an empty list
    • {} – an empty dict
    • () – an empty tuple
    • '' – an empty str
    • b'' – an empty bytes
    • set() – an empty set
    • an empty range, like range(0)
  • objects for which
    • obj.__bool__() returns False
    • obj.__len__() returns 0

A “truthy” value will satisfy the check performed by if or while statements. We use “truthy” and “falsy” to differentiate from the bool values True and False.

Truth Value Testing

Leave a Comment