Python Lambda

What is lambda in Python?

First, it is an expression, so called lambda expression. The expression evaluates to the value after the colon. Since it’s an expression, it can occur anywhere an expression can occur. For example, it can be assigned to a variable:

x=lambda a: a+2

It can appear in the return statement of a function:

def myfunc(n):
    return lambda a: a*n

Second, it is a function, an anonymous function. Since it is a function, it can can accept parameters:

x=lambda a: a+2
x(3)

 

def myfunc(n):
    return lambda a: a*n
myfunc(2)(5)

The function returns the value of the expression after the colon.

Did you like this?
Tip admin with Cryptocurrency

Donate Bitcoin to admin

Scan to Donate Bitcoin to admin
Scan the QR code or copy the address below into your wallet to send some bitcoin:

Donate Bitcoin Cash to admin

Scan to Donate Bitcoin Cash to admin
Scan the QR code or copy the address below into your wallet to send bitcoin:

Donate Ethereum to admin

Scan to Donate Ethereum to admin
Scan the QR code or copy the address below into your wallet to send some Ether:

Donate Litecoin to admin

Scan to Donate Litecoin to admin
Scan the QR code or copy the address below into your wallet to send some Litecoin:

Donate Monero to admin

Scan to Donate Monero to admin
Scan the QR code or copy the address below into your wallet to send some Monero:

Donate ZCash to admin

Scan to Donate ZCash to admin
Scan the QR code or copy the address below into your wallet to send some ZCash:

Leave a Reply