python的三元运算符
2013-07-11 00:10
190 查看
Yes, it was added in
version 2.5. It's frowned upon by some pythonistas, so keep that in mind.
The syntax is:
First
evaluated, then either
returned based on the Boolean value
of
if
to True
returned, else
returned.
For example:
Official documentation:
Conditional
expressions
Is
there an equivalent of C’s ”?:” ternary operator?
version 2.5. It's frowned upon by some pythonistas, so keep that in mind.
The syntax is:
a if test else b
First
testis
evaluated, then either
aor
bis
returned based on the Boolean value
of
test;
if
testevaluates
to True
ais
returned, else
bis
returned.
For example:
>>> 'true' if True else 'false' 'true' >>> 'true' if False else 'false' 'false'
Official documentation:
Conditional
expressions
Is
there an equivalent of C’s ”?:” ternary operator?
相关文章推荐
- python的三元运算符
- python 三元运算符
- python 三元运算符
- python三元运算符
- Python3 基础:条件判断和循环&三元运算符
- Python中的三元运算符
- python 中的三元运算符
- Python三元运算符替代方案
- Python3基础 三元运算符
- python条件表达式即三元运算符写法
- python三元运算符
- python 三元运算符
- python中的三元运算符
- python三元运算符
- Python三元运算符
- python回顾,yield特点,三元运算符,列表解析式,迭代器生成式,只可遍历一次的试码
- Python中的三元运算符
- Python 进阶语法六 —— 三元运算符
- Python语言技巧之三元运算符使用介绍
- python 下的三元运算符