DataScience - Python Lambda Functions

n = 3 p = 2

def test(n,p): return n**p

test(3,2)
Here, we create test function.

Lambda Function:

a = lambda n , p: n**p

a(3,2)

we use lambda keyword and take 2 inputs n,p; then after colon we put the output we want, then we store function inside variable 'a' and call it.
It is also called anonymous function bcoz this is a function without a name.

Do Not Use Lambda Function for Complex Functions, only use for simple functions.
Celsius to Farhenheit:

c_to_f = lambda c : (9/5)*c + 32

c_to_f(100)

Finding max:

finding_max = lambda x,y : x if x>y else y

finding_max(5,10)

Lambda Function to find length:

s = "karan"

find_len = lambda s : len(s)

find_len(s)