Maison >développement back-end >Tutoriel Python >python-三元运算和lambda
三元运算:
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等条件判断