Home  >  Article  >  Backend Development  >  Python 条件判断的缩写方法

Python 条件判断的缩写方法

WBOY
WBOYOriginal
2016-06-16 08:47:392058browse

return (1==1) ? "is easy" : "my god" //C#中的用法
其实,在Python中,是这样写的:
print (1==2) and 'Fool' or 'Not bad'
输出结果:
Not bad

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:Python struct.unpackNext article:Python交换变量