One of the most interesting aspects of the Python language are Lambda functions. For programmers who are skilled at reducing their codes into simple logical statements, Lambda functions help shrink the number of lines dramatically. In this article we shall go over what Lambda functions are and how to apply them in practical ways in Python.

Let’s begin!

The Benefits of Lambda

Say you have a function that multiplies any number you put into it by 10.

def mult_ten(original):
    return original * 10

number = mult_ten(5)

Image for post

Function Output

The function can actually be written as a literal one-liner. This is achieved through the use of lambda.

mult_ten = lambda i : i * 10
print(mult_ten(5))

Image for post

Exactly the Same Output

But wait, how about more complex functions such as the one below:

def mult_int(original, multiplier):
    return original * multiplier

number = mult_int(5, 11)

Image for post

Output of Two Variable Function

#data-science #tips-and-tricks #python #programming

Pythonic Tips & Tricks — Working with Lambda
3.45 GEEK