There is NO ternary operator in python but you can imitate like this, which is kinda cool:

val = ('val1', 'val2')[x < y]

… as an imitation of …

val = x < y ? 'val2' : 'val1'

blog comments powered by Disqus