In this tutorial, we will learn how to add multiple numbers in Python using different methods. Adding numbers is a common operation in programming and can be done using loops or built-in functions.

We will cover both approaches in this tutorial so you can easily apply these methods in your future projects.

### Step 1: Adding Multiple Numbers Using the for Loop

To add multiple numbers using a for loop, you can use the following steps:

- Initialize a variable to store the sum (we can call it “total”).
- Use a for loop to iterate through the numbers.
- Add each number in the loop to the variable “total”.
- Print the result after the loop has finished.

Here’s an example of a simple program that adds the numbers 1, 2, 3, 4, and 5:

1 2 3 4 5 6 7 |
total = 0 numbers = [1, 2, 3, 4, 5] for number in numbers: total += number print("The sum of the numbers is:", total) |

1 2 3 4 5 6 7 |
total = 0 numbers = [1, 2, 3, 4, 5] for number in numbers: total += number print("The sum of the numbers is:", total) |

**Output:**

The sum of the numbers is: 15

### Step 2: Adding Multiple Numbers Using the Built-in Function sum()

Python has a built-in function called **sum()** that can be used to add multiple numbers in a more concise way. It takes an iterable (like a list or tuple) as an argument and returns the sum of its elements.

Here’s the previous example reimplemented using the `sum()`

function:

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

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

**Output:**

The sum of the numbers is: 15

Notice how the code is more concise when using the `sum()`

function.

### Step 3: Adding Multiple Numbers with a Custom Function

You can also create a custom function to add multiple numbers. This can be useful if you need more control over the addition process or if you want to reuse the code in multiple places in your program. Here’s an example of a custom function that adds multiple numbers:

1 2 3 4 5 6 7 8 9 10 |
def add_numbers(numbers): total = 0 for number in numbers: total += number return total numbers = [1, 2, 3, 4, 5] result = add_numbers(numbers) print("The sum of the numbers is:", result) |

**Output:**

The sum of the numbers is: 15

## Conclusion

In this tutorial, we have demonstrated three different ways to add multiple numbers in Python: using a for loop, the built-in `sum()`

function, and a custom function.

By understanding these methods, you will be able to easily add multiple numbers to your Python projects.