Page 1 sur 1

definitions with lambda

Publié : mer. mars 13, 2019 3:35 pm
par compsystems
Hello

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
ok


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
error

Re: definitions with lambda

Publié : mer. mars 13, 2019 6:42 pm
par parisse
lambda is supported if the definition is on 1 line.