Fix Python – Python-equivalent of short-form “if” in C++ [duplicate]

Question

Asked By – huy

Possible Duplicate:
Python Ternary Operator

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

Now we will see solution for issue: Python-equivalent of short-form “if” in C++ [duplicate]


Answer

a = '123' if b else '456'

This question is answered By – SilentGhost

This answer is collected from stackoverflow and reviewed by FixPython community admins, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0