EN
Python - lambda expressions
0
points
In this article, we would like to show you lambda functions in Python.
Quick solution:
lambda arguments : expression
Practical examples
Example 1
In this example, we add 3
to the specified argument x
and reteurn the result.
result = lambda x: x + 3
print(result(2)) # 5
Output:
5
Example 2
In this example, we add arguments x
and y
together.
result = lambda x, y: x + y
print(result(1, 2)) # 3
Output:
3
Example 3
In this example, we multiply the given argument x
by 2
.
result = lambda x: x * 2
print(result(3)) # 6
Output:
6