开始以为Python中没有像其他语言一样的条件判断的缩写形式:
return (1==1) ? "is easy" : "my god" //C#中的用法
其实,在Python中,是这样写的:
print (1==2) and 'Fool' or 'Not bad'
输出结果:
Not bad
转帖注:
其实python支持原生的条件判断缩写,如下:
print 'Fool' if 1 == 2 else 'Not bad'
开始以为Python中没有像其他语言一样的条件判断的缩写形式:
其实,在Python中,是这样写的:
输出结果:
Not bad
转帖注:
其实python支持原生的条件判断缩写,如下:
print 'Fool' if 1 == 2 else 'Not bad'