Python天天美味(12) - 条件判断的缩写

开始以为Python中没有像其他语言一样的条件判断的缩写形式:
return (1==1? "is easy" : "my god" //C#中的用法

其实,在Python中,是这样写的:
print (1==2and 'Fool' or 'Not bad'

输出结果:

Not bad

 

Python 天天美味系列(总)

Python 天天美味(10) - 除法小技巧  

Python 天天美味(11) - 可爱的大小写
Python 天天美味(12) - 条件判断的缩写 

Python 天天美味(13) - struct.unpack   

Python 天天美味(14) - splitlines

...

posted @ 2008-05-04 11:08  CoderZh  阅读(5528)  评论(9编辑  收藏  举报