This is a common question I've seen, but really don't get the programming logic behind it. I'm sure it's a simple solution, but one that I have yet to understand.
Asked
Active
Viewed 335 times
0
-
1Because `and` returns the first value only if it is falsey. It *short circuits* when it can't produce a true value. – Martijn Pieters Dec 12 '17 at 15:26
-
Python evaluates `x and y` as `if x is false, then x, else y`. Since `bool(2)` evaluates to `True`, python returns `3`. – Chris Mueller Dec 12 '17 at 15:33