Lambda functions in Python: what are they?

Ever encounter a python script with a “lambda” lurking somewhere in the blocks of code? Didn’t know what to make of it? I’ve got you covered…

Put simply, a lambda function is a small anonymous function. It is mostly used for cases that do not require a separate function for whatever reason.

Syntax is relatively straightforward:

 # Syntax: lambda inputs: outputs
lambda_function = lambda x,y: x + y # Inputs are x and y. Output is (x + y)
lambda_function(2,3) # Result is 5

Leave Comment

Het e-mailadres wordt niet gepubliceerd. Vereiste velden zijn gemarkeerd met *