Python ternary operator

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.


PEP 308 adds a ternary operator:

foo = "True" if test else "False"

It's been implemented since Python 2.5


这个看起来更像原始三元:

foo=a and b or c
链接地址: http://www.djcxy.com/p/7394.html

上一篇: 在Python中替换三元运算符的最好方法是什么?

下一篇: Python三元运算符