The standard use of the ternary operator is, i.e.:
a = 1 if some_condition else 2
Just today, I realized something like this is perfectly legal:
do_something() if some_condition else do_something_else()
For example:
print(1) if a == 1 else print(2)
instead of:
if a == 1:
print(1)
else:
print(2)
In my opinion, this is more compact, readable and prettier. I see that it would be harder to get return values from this type of expression (perhaps the way would be to wrap everything in parentheses). What do you think?
P.S. I know it's not typical Q&A content, but I have never even seen this use of the ternary operator mentioned, and I think it clearly improves some aspects of Python coding.