top of page

Truthy and Falsy Values in Python

Updated: Apr 8, 2020



Takeaway from the freecodecamp article


Falsy Values include:


  • Sequences & Collections: Empty lists, dictionaries, tuples, sets, strings, range(0)

  • Numbers: Zero of any numeric types including integer (0), float (0.0), complex(0Abc)

  • Constants: none, False


 

 

Truthy Values Include:

non-zero numeric values, non-empty sequences and collections, True


Python built-in function: bool() function to check whether a value is truthy or falsy



 

Benefits:

  • More Concise code with IF or WHILE loop

  • Make custom objects truthy and falsy values by adding the special method __bool__( )


jupyte notebook example

10 views0 comments

Recent Posts

See All
bottom of page