Python sum() Function
Sums all the items in an iterator
Syntax
Python
Copy Code
sum(iterator)
Parameters
Parameter | Description |
---|---|
iterator |
Required. An iterator containing the items to be summed. |
Example
Python
Copy Code
total = sum(range(1, 100)) print('The sum of numbers from 1 to 100 is: ', total)
Output
The sum of numbers from 1 to 100 is: 4950