Compared to the code below, does python's "logical short-circuit" rule fail? If so, why is it not working?'
print([1].append(3) or 2)
The result is '2',the 'logical short circuit' principle seems to have failed
print([1,3] or 2)
the result is '[1,3]',the'logical short circuit' principle is valid.
Calls to
append, like[1].append(3), returnNone(they update the list, but that's not visible in this snippet of code).print([1].append(3) or 2)is likeprint(None or 2)which is likeprint(2)becauseNoneis false-ish.For example: