How to write a lambda function in Python

To write a lambda function (technically inline function) in Python, you can use the “lambda” keyword. You can following example to see the basic usage of a lambda function:

Python 3.7.0 (default, Jun 29 2018, 20:13:13)
[Clang 9.1.0 (clang-902.0.39.2)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> add_function = lambda a,b: a+b
>>> add_function(2,3)

Leave a Reply

Your email address will not be published. Required fields are marked *