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
Comentários