Sum () function in Python
The built-in function sum () in Python returns the sum of all numbers in iterable.
The built-in function sum () in Python returns the sum of all numbers in iterable.
Sum function sum ()
sum(iterable, start)
The sum () function starts adding from left to right
iterable
: built-in iterable (like list, string, dict) needs to be summed, usually numbers.start
: value added to the value returned from iterable. The default value is 0.
Value returned from sum ()
The sum () function returns the sum of start
and iterable component items.
For example: How sum () works in Python
numbers = [2.5, 3, 4, -5]
# không truyền tham số start
numbersSum = sum(numbers)
print(numbersSum)
# start = 10
numbersSum = sum(numbers, 10)
print(numbersSum)
Run the program, the result is:
4.5
14.5
See also: Built-in Python functions
Update 27 May 2019
sum () functionpython functionsum () function syntaxavailable python functionpython documentationpython learning
You should read it
- Max () function in Python
- The ord () function in Python
- The map () function in Python
- The oct () function in Python
- The function id () in Python
- The function set () in Python
- The next () function in Python
- Complex () function in Python
- Zip () function in Python
- Int () function in Python
- The input () function in Python
- The pow () function in Python
Maybe you are interested
What does the 'super slow' 7680fps movie recording feature on the Mate 30 Pro do? Hitman Sniper famous game is being free on iOS and Android How to create slow motion videos on Android? 8 ways to win people's hearts 6 tips to help you get out of debt Changing these 10 ways of speaking will help you advance like 'windy kites'.