Where is the ternary operator in Python —27 August 2009
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'
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'