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