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'
Written by Keith DiMatteo
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Python
Authors
Related Tags
#python
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#