📖 Beginning Python Programming /
Module: Defining Functions

Defining functions

📖 Beginning Python Programming / Defining Functions / Defining functions

Lambda function

Lambda function is a one-line function without name.
# Here is a lambda function declaration
# But we don’t have name to reference it.
lambda x: x*x
# Here is a lambda with name.
square = lambda x: x*x
print(square(10))
# Better usage, when we need an adhoc one-line function.
# Given a list
# [1,2,3,4,5,6,7,8,9]
L = list(range(1,10))
print(L)

# We can transform the list
L2 = list( map(lambda x: x*x, L) )
print(L2)