Add Two Number Using Lambda Function

Here we are going to use Python Lambda function for addition of two number with Python

Python3




# Define a lambda function to add two numbers
add_numbers = lambda x, y: x + y
 
# Take input from the user
num1 = 1
num2 = 2
 
# Call the lambda function to add the two numbers
result = add_numbers(num1, num2)
 
# Print the result
print("The sum of", num1, "and", num2, "is", result)


Output:

The sum of 1 and 2 is 3

How to Add Two Numbers in Python – Easy Programs

Learn easy techniques and codes to add numbers in Python. Adding numbers in Python is a very easy task, and we have provided you 7 different ways to add numbers in Python.

Given two numbers num1 and num2. The task is to write a Python program to find the addition of these two numbers. 

Examples:

Input: num1 = 5, num2 = 3
Output: 8
Input: num1 = 13, num2 = 6
Output: 19

There are many methods to add two number in Python:

  • Using “+” operator
  • Defining a function that adds two number
  • Using operator.add method
  • Using lambda function
  • Using Recursive function

Each of these methods have been explained with their program below.

Similar Reads

Add Two Numbers with “+” Operator

Here num1 and num2 are variables and we are going to add both variables with the + operator in Python....

Add Two Numbers with User Input

...

Add Two Numbers in Python Using Function

In the below program to add two numbers in Python, the user is first asked to enter two numbers, and the input is scanned using the Python input() function and stored in the variables number1 and number2....

Add Two Numbers Using operator.add() Method

...

Add Two Number Using Lambda Function

This program show adding two numbers in Python using function. We can define a function that accepts two integers and returns their sum....

Add Two Numbers Using Recursive Function

...

Contact Us