Possible Duplicate:
Ternary conditional operator in Python
If I have some code like:
x = foo ? 1 : 2
How should I translate it to Python? Can I do this?
if foo: x = 1 else: x = 2
Will x still be in scope outside the if / then blocks? Or do I have to do something like this?
x = None if foo: x = 1 else: x = 2
Use the ternary operator(formally conditional expression) in Python 2.5+.