An example Python method for executing triple expressions:
i = 5 if a > 7 else 0
means
if a > 7: i = 5 else: i = 0
This is really useful when using lists or sometimes in return statements, otherwise I'm not sure if this helps in creating readable code.
The readability issue has been discussed in detail in this recent SO question better than using the if-else statement in python .
It also contains various other smart (and somewhat confusing) ways to accomplish the same task. It is worth reading only based on these posts.
Levon Jul 17 '12 at 19:15 2012-07-17 19:15
source share