+ 7

print(False or 4) print(4 or False) print(4 or True) print(True or 4)

Why does For print(False or 4) output is 4 print(4 or False) output is 4 print(4 or True) output is 4 print(True or 4) output is True

17th Jul 2020, 12:41 PM
Gajendra Pal
4 ответов
+ 4
Thnx
17th Jul 2020, 2:20 PM
Gajendra Pal
+ 3
Gajendra you are welcome
17th Jul 2020, 2:21 PM
Infinite
Infinite - avatar
+ 2
Or returns the first truthy when included in a code. In the case of the first two, 4 is output because 4 is the first truthy value. It doesn't matter whether it comes before or after false... While in the third case, both 4 and true are truthy. 4 is returned because it is the first truthy value encountered when code was executed. Same as in the last case, true is returned because it is the first truthy value encountered.. In a case where both values are false, the last value is returned. I hope this answers your question.
17th Jul 2020, 12:58 PM
Infinite
Infinite - avatar
+ 1
short-circuiting
19th Jul 2020, 7:09 AM
madeline
madeline - avatar