+ 2
print( 7 and '0' and 1)
What will be the output? I know answer and little of it how, but i want someone to explain in detail. What is the output and how it does come? Saw this somewhere, and was curious to know answer from all of u here.
5 Answers
+ 6
ā
Ā«D.Connect_ZoneĀ» In short:
"and" returns the first falsy value. If there is not then it returns the last value (truthy).
"or" returns the first truthy value. If there is not then it returns the last value (falsy)
In both cases:
All expressions after the returned one are not evaluated.
+ 7
If we have a boolean expression like:
v1 and v2 and v3 and v4........
The truthy of every value is checked from left to right and the first falsey value is returned. If there is not a falsy value the last one is returned. That's why 1 is the answer.
Abhishek Patel "and" does not return 1 for two true values. It returns the last value if and only if both operands are truthy. Otherwise the first falsey value is returned.
+ 2
1
Because, all have some value. "and" return '1' for two true values
+ 1
Kevin Star Nice Answer.
Boolean Expression.. if there's not a false value returns last truthy value.... cool answer.
+ 1
none empty strings are considered true. '0' is not empty. if you evaluate left to right all are true to the last one.