Ternary conditional operator in Python
var foo = (test) ? "True" : "False";
在Python中会是什么样子?
使用Python2.7,如果这有区别的话。
PEP 308 添加三元运算符:
foo = "True" if test else "False"
它是从Python2.5开始实现的
foo=a and b or c