tags:

views:

593

answers:

2

Is there a way to write this C/C++ code in Python? a = (b == true ? "123" : "456" )

Thanks so much!

+20  A: 
a = '123' if b else '456'
SilentGhost
This ternary operator was introduced in Python 2.5.
Dave Webb
thanks! exactly what i was looking for. couldn't find it on the python docs website.
huy
For future reference, here's the Python documentation for the conditional expression: http://docs.python.org/reference/expressions.html#boolean-operations
Greg Hewgill
+2  A: 

see here for more info

ghostdog74