What is the result of the following?
num1 = 0 num2 = 2 print(num1 and num2 > 1) print(num1 or num2 == 0)
A common mistake is to only put the comparison in the second operant in an and or or expression.
and
or
In the previous examples, python is checking if num1 itself is True or False, not comparing it with 0.
bool()
print(bool(True)) # True print(bool(False)) # False
Python considers these as False:
False
None
0
0.0
""
[]
{}
()
set()
print(bool(42)) # True print(bool("hello")) # True print(bool([1, 2])) # True
print(bool(0)) print(bool("")) print(bool([])) print(bool(None))
bool(value)