+ 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
4 ответов
+ 4
Thnx
+ 3
Gajendra you are welcome
+ 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.
+ 1
short-circuiting