Can lambdas have multiple arguments?

QuestionsQuestions8 SkillsProPython Built-in FunctionsDec, 02 2025
095

Yes, lambda functions in Python can have multiple arguments. You can define a lambda function with as many arguments as you need, separated by commas. The syntax remains the same:

lambda arg1, arg2, ...: expression

Example of a Lambda Function with Multiple Arguments:

Here’s an example that takes two arguments and returns their sum:

add = lambda x, y: x + y
result = add(5, 3)  # result will be 8

Another Example:

You can also use a lambda function with multiple arguments in a higher-order function like map():

pairs = [(1, 2), (3, 4), (5, 6)]
sums = list(map(lambda x, y: x + y, *pairs))  # Unpacking pairs
# sums will be [4, 7, 11]

In this example, the lambda function takes two arguments from each tuple in the pairs list and returns their sum.

0 Comments

no data
Be the first to share your comment!