python - 能否解释一下这种特别的 if 语句?
PHP中文网
PHP中文网 2017-04-17 14:27:47
0
2
287
print 'False' if (False) else 'True'

感觉有点类似 C/C++ 中的三目运算符。我在教程中都没有看到过相关的介绍。这是什么语法?

PHP中文网
PHP中文网

认证0级讲师

reply all(2)
伊谢尔伦

https://docs.python.org/2/reference/expressions.html#conditional-expressions

This is the syntax, just understand it.

刘奇

print 'False' if (False) else 'True'

That is, if (False) ? printf("False") : printf("True")
in C, JAVA and other languages if A?B:C converted to python is B if A else C

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!