Python basics: Lambda with examples
Published in
1 min readNov 16, 2019
Introduction:
A lambda function can take any number of arguments, but can only have one expression.
Example 1:
A lambda function that adds 5to the number passed in as an argument, and prints the result:
newLam = lambda x: x+ 5
print(newLam(5))output — 10
Example 2:
A lambda function that multiplies argument X with argument Y and prints the result:
newLam = lambda x, y: x* y
print(newLam(5, 5))output — 25 (5 * 5)
Example 3:
A lambda function that sums argument a, b, and c and prints the result:
x = lambda a, b, c : a + b + c
print(x(5, 6, 2))output — 13