Last Updated: February 25, 2016
·
301
· kdimatteo

Ternary Operations

Short hand if/else condition checks a lot in PHP, JS, and AS:

someVar = (someValue == true) ? "apples", "bananas"

In python via a list comprehension:

someVar = ("bananas","apples")[someValue == true]

For example:
age = 99
status = ("working", "retired")[age>65]
print status
# yields 'retired'