[–] mikeklaas 15y ago ↗ Python has had a "quite" ternary operator for years now: expr if cond else expr [–] 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 ago ↗ That would be way odder. In Python, colons are used for statements, not expressions. Nothing wrong with the conditional expression as it is. [–] lvh 15y ago ↗ How 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.
[–] 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 ago ↗ That would be way odder. In Python, colons are used for statements, not expressions. Nothing wrong with the conditional expression as it is. [–] lvh 15y ago ↗ How 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.
[–] rbonvall 15y ago ↗ That would be way odder. In Python, colons are used for statements, not expressions. Nothing wrong with the conditional expression as it is.
[–] lvh 15y ago ↗ How 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.
4 comments
[ 3.0 ms ] story [ 19.6 ms ] threadIMNHSO, precisely for the reason you mention, that would be much more of a hack.