4 ms·
But this odd order is a hack for the fact that python distinguishes between expressions and statements and won't change. It should be: result = if cond: e
by artsrc 15y ago
But this odd order is a hack for the fact that python distinguishes between expressions and statements and won't change. It should be:
result = if cond: expr else: expr
- rbonvall 15y agoThat would be way odder. In Python, colons are used for statements, not expressions. Nothing wrong with the conditional expression as it is.
- lvh 15y agoHow is the order important? Why couldn't Python have implemented: result = cond then expr1 else expr2 (Except that it's harder to read, which is why Python doesn't have that.) IMNHSO, precisely for the reason you mention, that would be much more of a hack.