58
votes

Possible Duplicate:
Ternary conditional operator in Python

var foo = (test) ? "True" : "False";

What would this look like in Python?

Using Python 2.7 if that makes a difference.

2

2 Answers

92
votes

PEP 308 adds a ternary operator:

foo = "True" if test else "False"

It's been implemented since Python 2.5

-1
votes

This one looks a bit more like original ternary:

foo=a and b or c