Languages
[Edit]
EN

Python - lambda expressions

0 points
Created by:
FryerTuck
319

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

Python - fundamentals

Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join