W3docs

Sum a list of numbers in Python

Here is a code snippet that demonstrates how to sum a list of numbers in Python:

Here is a code snippet that demonstrates how to sum a list of numbers in Python:

Sum a list of numbers in Python using the sum function

numbers = [1, 2, 3, 4, 5]
total = sum(numbers)
print(total)

<div class="alert alert-info flex not-prose"> Watch a course <span class="hidden md:block">Watch a video course </span> Python - The Practical Guide</div>

You can also use a for loop to sum the list of numbers:

Sum a list of numbers in Python using a for loop

numbers = [1, 2, 3, 4, 5]
total = 0

for num in numbers:
    total += num

print(total)

Both the above code snippet will give you the sum of the list of numbers.