How to add all numbers in a list in Python

Hi everyone, today in this tutorial let us see how to add all numbers in a list in Python. Basically, we can add numbers in a list in many ways, like in other programming languages we can use loops(for loop, while loop). We can also use lambda.

But in our tutorial let us see how to add elements in a list using built-in function and slicing. This way of doing is better than using other methods. This is because slicing is an important technique in machine learning.

How can you add all numbers in a list in Python

Let us now see how to add all numbers in a list using a built-in function. We use sum() which is a built-in function in Python programming language.


The sum() is a built-in function as said earlier. This function will work only when numeric values are given to it, this will not work when alphabets are given to it or when numbers are given in the form of string it will show errors. This function basically sums up the numbers that are given to this and return the sum of numbers given in it.

Now, let us see the code.




Let us now see the usage of for loop in sum() function.

print(sum(i for i in p))



You can also use the sum() function to add a constant value for the sum total of the list. The syntax of the sum() function is sum(iterable, start). So here, start means a value that can be summed up to the list and iterable means list, tuple, dict, etc.,




Now, let us see how to add a list of numbers using the slicing method.


This slicing is an amazing feature given to us in Python language. This way of writing the code and analyzing the data plays a key role in Machine learning and Deep learning techniques.

Let us now have a look on our code.




You may also read:

One response to “How to add all numbers in a list in Python”

  1. EclipseYT says:

    Thanks, this was super useful. i was having much trouble adding up a list.

Leave a Reply

Your email address will not be published.