+ 2
print(0 or 2)
Why print(0 or 2) Outputs: 2 I though that 0 - False, 2 - True so False or True Why is this?
4 Answers
+ 1
a or b: a if bool(a) else b
a and b: a if not bool(a) else b
+ 6
0 is a False statement
2 is a True statement
The 'or' operator will chose the first correct statement, which is 2
+ 3
Yannick Daniel Gibson any number different than 0 is considered to be a True statement.
if 2:
print("first test")
if -6:
print("second test")
if 0:
print("third test")
OUTPUT:
first test
second test
+ 1
Had to think 'bout how operators work, actually, my understanding was a bit off, but now I get it. Thanks!



