Skip to content

[python] ternary conditional operator

Myungchul Shin edited this page Apr 21, 2016 · 1 revision
x = 'true' if 0 < 3 else 'false'
y = ('false', 'true')[0 < 3]
z = (lambda:'false', lambda:'true')[0 < 3]()
w = {True:'true', False:'false'}[0 < 3]
print x, y, z, w
....
true, true, true, true
Clone this wiki locally