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

return (1==1? "is easy" : "my god" //C#中的用法


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

print (1==2and 'Fool' or 'Not bad'


输出结果:

Not bad

 

转帖注:

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

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

 

posted on 2013-05-15 12:12  一个人的天空@  阅读(527)  评论(0编辑  收藏  举报