+ 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.

4th Jan 2020, 6:21 PM
ā˜…Ā«D.Connect_ZoneĀ»
ā˜…Ā«D.Connect_ZoneĀ» - avatar
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.
4th Jan 2020, 6:53 PM
Kevin ā˜…
+ 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.
4th Jan 2020, 6:35 PM
Kevin ā˜…
+ 2
1 Because, all have some value. "and" return '1' for two true values
4th Jan 2020, 6:30 PM
Abhishek Patel
+ 1
Kevin Star Nice Answer. Boolean Expression.. if there's not a false value returns last truthy value.... cool answer.
4th Jan 2020, 6:43 PM
ā˜…Ā«D.Connect_ZoneĀ»
ā˜…Ā«D.Connect_ZoneĀ» - avatar
+ 1
none empty strings are considered true. '0' is not empty. if you evaluate left to right all are true to the last one.
4th Jan 2020, 6:53 PM
Bahhaāµ£
Bahhaāµ£ - avatar