I know it's frowned upon by some, but I like using Python's ternary operator, as it makes simple if/else statements cleaner to read (I think). In any event, I've found that I can't do this:
>>> a,b = 1,2 if True else 0,0
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: too many values to unpack
The way I figured the ternary operator works is that it essentially builds the following:
if True:
a,b = 1,2
else:
a,b = 0,0
Could someone explain why my first code sample doesn't work? And, if there is one, provide a one-liner to assign multiple variables conditionally?