Just a small question about ternary conditional operator which has confused me for a long time.
Code for example (python 2.7):
>>> x, y = None, 3
>>> x, y
(None, 3)
>>> (x == None and x or y)
3
>>> (x != None and x or y)
3
>>> (x if x == None else y)
The third and forth lines are old-style conditional operator. Both give the same result. And obviously, the former takes "wrong" result. Maybe it's not wrong according to python. But it's very easy to make the mistake in program and without explicit error.
The fifth line are new-style from version 2.5 according to the book "Core python programming" (Wesley J. Chun) and its return is right.
Does someone know something about this?