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