I think understand that print('a' or 'b') returns 'a', since x or y gives x if x is true, which 'a' can be interpreted as? But why does print('a' and 'b') return 'b'?
Asked
Active
Viewed 770 times
-1
-
@ApplePie the top answer on that question looks correct, but boy is it wordy! – Mark Ransom Nov 06 '20 at 20:11
1 Answers
1
or
returns the first value if it's truthy, otherwise it returns the second value. Meanwhile, and
returns the first value if it's falsy, otherwise it returns the second value. This is consistent with the definition of the operators:
True or _ = True
False or x = x
True and x = x
False and _ = False
Also, all non-empty strings are truthy.

Aplet123
- 33,825
- 1
- 29
- 55