Learning Python - 7th day (Night - 1)

 Watched tutorial: Click Here

I have learnt about  Lambda tonight.

lambda (minimizing a function())

How does this work?

Okay, to understand this I am using a normal function first. Let's name the function as getNum(n)

Example:

def getNum(n):
return n+10
print(getNum(5))

Output: 15

This is a normal function I already learned, right? But can I shrink the function to a smaller one?

Yes! There is a way for shrinking functions in one line for one time use. 

To do this we need to use lambda.

The structure for lambda is: 

lambda arguments: function

For example:

a = lambda n: n+10
print(a(5))

Output: 15

This is how you can use lambda to make shorter functions!

Comments

Popular posts from this blog

Husband's Affair with Step Daughter Ends in Grisly Murder (True Crime Documentary)