Home > Article > Backend Development > python-ternary operations and lambda
Ternary operation:
name = "GOGOGO" if True else "HAHA"
is equivalent to:
if True: name = "GOGOGO" else: name = "HAHA" print (name)
Execution result:
GOGOGO
lambda:
f2 = lambda a1,a2: a1+a2 t = f2(1,2) print (t)
is equivalent to:
Python code
def f2(a1,a2):
return a1 +a2
t = f2(1,2)
lambda cannot be judged using if, else and other conditions