All Python Tutorial Links

Add all numbers in a list in Python

 Add all numbers in a list in Python

Hello Programmers!

In this tutorial, I will teach you how to add all numbers in a list in python. This is an intermediate concept of python. If you have any questions then you can comment me below or mail me at arefinanwar112@gmail.com. So let's get started.

Sum of numbers in the list is required everywhere. Python provides an inbuilt function to do this job easily. The function name is sum() which sums up the numbers in the list.

Syntax:

sum(iterable)


sum(b)

In the above syntax, the numbers of the "b" list will be summed.


Below is the Python implementation of the sum() function

b = [1, 2, 3, 4, 5, 1, 6, 9]

Sum = sum(b)

print(Sum)


Output

31


Note: The sum() can be only used in numeric lists. It cannot be used in character lists. If you use this sum() in the character list then you will see an error.


Congratulations! Now you know how to add all numbers in a list in Python. This was a very important and basic concept of python. If you have any questions then you can comment me below or mail me at arefinanwar112@gmail.com.

Happy Coding:)


list in python,python,python list,lists in python,python lists,list,search an element in a list,multiply all numbers in the list,python tutorial,small

Comments