Python - Truthy and Falsy Values
Python tip:
In Python, individual values can evaluate as either True or False. Values that evaluate to
True
are "Truthy", and values that evaluate toFalse
are "Falsy".By default, an object is considered Truthy, unless its
__bool__()
method returnsFalse
or__len__()
returns0
.👇
empty_list = [] empty_touple = () empty_dict = {} empty_set = set() empty_string = "" empty_range = range(0) print(bool(empty_list)) # False print(bool(empty_touple)) # False print(bool(empty_dict)) # False print(bool(empty_set)) # False print(bool(empty_string)) # False print(bool(empty_range)) # False print(bool(0)) # False print(bool(0.0)) # False print(bool(0j)) # False print(bool(None)) # False print((bool(1))) # True print((bool(" "))) # True