Menu Close

Python sum Function

In this article, we are going to learn all about Python sum built-in function to calculate sum of all the items in iterable.

In the previous tutorial, we have seen lots of Python built-in functions along with examples.

Python sum function

Python sum is a built-in function that is used to return the sum of all the items in an iterable. Iterable can be a tuple, list, and set.

Syntax:

The syntax of sum function in Python is:-

sum(iterable, start)

Parameter:

sum function accepts two parameters.

  • iterable:- Required, The sequence to calculate the sum.
  • start: Optional, A value that is added to return value.

Return Value:

The return value python sum function is added value.

Python sum function example:

Here will take some examples to understand sum function in Python.

Example 1:

Sum function in Python with one parameter.

result = sum([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
print(result)

Output will be:- 55

Example 2:

Sum function in Python with second parameter.

result = sum([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 45)
print(result)

Output will be:- 100

Conclusion

So that, In this article, you have learned all about the Sum function in Python along with examples.
Python sum is the best function to calculate items of iterable. If this article helpful for you, please share and keep visiting for further python tutorials.

Python built-in functions

Fore more information:- Click Here

Previous Article
Next Article

Was this post helpful?

Related Posts