Re:A few things to remember while coding in Python
by iki23 on Sunday May 20, 2012 @04:48AM
(#3998323)
Yes, but why? Actually, it's No, because python culture aims to use one way to do thing, the least surprising one. In this case it's:
[ Parent
| on HN ]
Re:A few things to remember while coding in Python
by SoftwareMaven on Sunday May 20, 2012 @05:07PM
(#4000109)
Because that "if" is a statement whereas the ternary expression is, well, an expression. There are places expressions can be used that statements can't (eg lambdas) and that x or [] won't work (eg when x is False).
That said, people still seem to favor your form as the more Pythonic way. Personally, I think that's just because the ternary expression is relatively new.