how to use sum function in python?

Today, We want to share with you sum function in python.In this post we will show you sum function in dictionary python, hear for sum of two numbers in python we will give you demo and example for implement.In this post, we will learn about fibonacci series in python with an example.

how to use sum formula in python

write a python function to sum all the numbers in a list?
Python sum() Function
The syntax of the sum() function is:

sum(iterable, start)

Example 1: Simple Example

a = (1, 2, 3, 4, 5)
x = sum(a, 7)
print(x)

Working of Python sum()

totalnos = [2.5, 3, 4, -5]

# start parameter is not provided
totalnos_sum = sum(totalnos)
print(totalnos_sum)

# start = 10
totalnos_sum = sum(totalnos, 10)
print(totalnos_sum)

Example 3: Find the sum of all the numbers in a list

def sum(totalnos):
    total = 0
    for x in totalnos:
        total += x
    return total
print(sum((9, 6, 5, 0, 4)))

I hope you get an idea about python sum list of lists.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

Leave a Comment