Unit 3 - Lesson 4

27.1.1. Introduction to Lambda Function

(a) Anonymous functions are also called lambda functions.
(b) Lambda functions can be used anywhere we need a regular function objects.
(d) The expression is evaluated first and a value is returned.

27.1.2. Simple lambda example

tax = lambda salary: salary*20/100# write the expression here
	
salary = int(input("Please enter your salary: "))
print("Tax to be paid is", tax(salary))

27.1.3. Writing an example for Anonymous function

doublenum = lambda a: a*2

#complete the code..
a = int(input("a: "))
print(doublenum(a))

27.1.4. Understanding map function

def squares(x):
	return x**2
#fill in the missing code..
list1 = list(map(int,input().split(",")))


print(list(list(map(squares,list1))))

27.1.5. Understanding Filter function

a = list(map(int,input().split(",")))

#fill in the missing code

print(list(filter(lambda x: x%2==0, a)))

Post a Comment

Cookie Consent
We serve cookies on this site to analyze traffic, remember your preferences, and optimize your experience.
Oops!
It seems there is something wrong with your internet connection. Please connect to the internet and start browsing again.
AdBlock Detected!
We have detected that you are using adblocking plugin in your browser.
The revenue we earn by the advertisements is used to manage this website, we request you to whitelist our website in your adblocking plugin.