Python三值操作

2024-06-07 00:30:19 发布

您现在位置:Python中文网/ 问答频道 /正文

Possible Duplicate:
Ternary conditional operator in Python

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

在Python中会是什么样子?

使用Python2.7,如果这有区别的话。


Tags: intestfalsetruefoovaroperatorconditional
2条回答

这个看起来有点像原始的三元组:

foo=a and b or c

PEP 308添加三元运算符:

foo = "True" if test else "False"

它是从Python2.5开始实现的

相关问题 更多 >