Python is a popular high-level programming language used by developers for various purposes, such as data analysis, web development, and machine learning. In this article, we will discuss how to add two numbers in Python, one of the basic arithmetic operations that every programmer needs to know.

Method 1: Using the plus (+) Operator

Python provides a simple way to add two numbers using the plus (+) operator. Here is an example:

a = 10
b = 5
sum = a + b
print("The sum of", a, "and", b, "is", sum)

In this code, we define two variables a and b, with values of 10 and 5, respectively. We then add these two numbers using the plus (+) operator and assign the result to a variable called sum. Finally, we print the result using the print() function.

Method 2: Using the sum() Function

Python also provides a built-in function called sum() that can be used to add multiple numbers at once. Here is an example:

numbers = [1, 2, 3, 4, 5]
total = sum(numbers)
print("The sum of", numbers, "is", total)

In this code, we define a list of numbers [1, 2, 3, 4, 5] and use the sum() function to add them together. The result is then assigned to a variable called total, and we print the result using the print() function.

Method 3: Using the reduce() Function

Python also provides a functional programming tool called reduce() that can be used to apply a function to a sequence of elements. Here is an example of using reduce() to add two numbers:

from functools import reduce

return x + y

numbers = [10, 20, 30, 40, 50]