What is the explanation for this behavior in Python?
a = 10
b = 20
a and b # 20
b and a # 10
a and b evaluates to 20, while
The documentation explains this quite well:
The expression
x and yfirst evaluatesx; ifxis false, its value is returned; otherwise,yis evaluated and the resulting value is returned.
And similarly for or which will probably be the next question on your lips.
The expression
x or yfirst evaluatesx; ifxis true, its value is returned; otherwise,yis evaluated and the resulting value is returned.