Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

python or

# If a is truthy,
# returns a, otherwise b

# Use bool(<value>) to know whether a value
# is truthy or falsy

#  a  b | True | False
# -------+------+-------
#  True  | a    | a
# -------+------+-------
#  False | b    | b

print(True or True) # True
print(True or False) # True
print(False or False) # False

print(1 or 0) # 1 is truthy -> 1
print([] or {}) # [] is falsy -> {}
print([] or {} or ()) # "([] or {}) or ()" -> "{} or ()" -> "()"
print([1, 2] or (3, 4)) # [1, 2] is true -> [1, 2]
 
PREVIOUS NEXT
Tagged: #python
ADD COMMENT
Topic
Name
6+6 =