三元运算:
name = “gogogo” if true else “haha”
等同于:
if true:
name = “gogogo”
else:
name = “haha”
print (name)
执行结果:
gogogo
lambda:
f2 = lambda a1,a2: a1+a2
t = f2(1,2)
print (t)
等同于:
python代码
def f2(a1,a2):
return a1+a2
t = f2(1,2)
lambda无法使用if,else等条件判断