开始以为Python中没有像其他语言一样的条件判断的缩写形式:

Python天天美味(12) - 条件判断的缩写(转)return (1==1? "is easy" : "my god" //C#中的用法


其实,在Python中,是这样写的:

Python天天美味(12) - 条件判断的缩写(转)print (1==2and 'Fool' or 'Not bad'


输出结果:

Not bad

 

转帖注:

其实python支持原生的条件判断缩写,如下:

print 'Fool' if 1 == 2 else 'Not bad'

 

相关文章: