Quick actions

cmd+k|ctrl+k

Navigation

Languages

Truthy and Falsey

Snippet info

Language

Python

Visibility

public

Author

yogilight

Created

2025-04-10T12:31:34.872629Z

Updated

2025-04-10T12:31:34.872629Z

#Truthy and falsy values in Python refer to the boolean evaluation of 
#non-boolean objects. When a value is used in a boolean context, such as in an
#if statement or a while loop, Python implicitly converts it to a boolean value
#(True or False). Values that evalute to True are considered "truthy," while 
#those that evalue to False are considered "falsy."

#The following values are considered falsy in Python:
# False
# None
# 0(integer)
# 0.0(float)
# 0j(complex number)
# ''(empty string)
# [](empty list)
# ()(empty tuple)
# {} (empty dictionary)
# set() (empty set)
# range(0) (empty range)

password = '' #empty string considered false
username = 'johnny'

if password and username:
    print('you are old enough to drive, and have a license')
else:
    print('you are not of age')
INFO