Is it possible to define functions with lambda for a block of expressions?, currently only works for an expression
def add_(x, y): return x + y
add_ = lambda x, y : x + y # ok
now
Code : Tout sélectionner
def calculator( oper, a, b ):
if "addition" == oper:
return a + b
elif "subtraction" == oper:
return a - b
elif "multiplication" == oper:
return a * b
elif "division" == oper:
return a / b
else:
return None
but
Code : Tout sélectionner
calculator = lambda oper, a, b:
if "addition" == oper:
return a + b
elif "subtraction" == oper:
return a - b
elif "multiplication" == oper:
return a * b
elif "division" == oper:
return a / b
else:
return None