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
The syntax of sum function in Python is:-
sum function accepts two parameters.
- iterable:- Required, The sequence to calculate the sum.
- start:– Optional, A value that is added to 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.
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
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
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