Sobes.tech
Junior — Middle

What are the distinctive features of the Lambda function in programming?

sobes.tech AI

Answer from AI

A lambda function in Python is an anonymous function defined using the lambda keyword. Key features:

  • Single-line function without a name.
  • Can accept any number of arguments, but the body must be an expression whose result is returned.
  • Used for simple operations when you don't want to write a full function.

Example:

# Regular function
def square(x):
    return x * x

# Lambda function
square = lambda x: x * x

print(square(5))  # 25

Lambda functions are often used in higher-order functions like map(), filter(), sorted() with a sorting key.