We know that a function in Python is defined using the def keyword. Similarly, a lambda function is defined using the lambda keyword. Consider the below example to deeply understand the difference between the two:
# Normal function def sq(x): return x*x # Lambda function lambda_sq = lambda x: x*x # Calling the normally # Defined function print(sq(10)) # using the lambda function print(lambda_sq(10)) }
The above example illustrates 2 functions calculating the square of a number. Without lambda, we have to create a function sq(x), and then return the square. On the other hand, with lambda, the whole function has boiled to a single line. Lambda does not require a return statement.