Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

What is an anonymous function in Python?

In the given code

a = [(1, 2), (4, 1), (9, 10), (13, -3)]
a.sort(key=lambda x: x[1])
print a

Is the lambda function an anonymous function?


1 Answer
Rajendra Dharmkar

In Python, anonymous function is a function that is defined without a name. While normal functions are defined using the def keyword, in Python anonymous functions are defined using the lambda keyword. Hence, anonymous functions are also called lambda functions.

 If we run the given code we get the following output

C:/Users/TutorialsPoint1/~.py
[(13, -3), (4, 1), (1, 2), (9, 10)]

Advertisements

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.