The method of summing in python: use sum syntax to sum [sum(iterable[, start])], where iterable is an iterable object and start is a parameter that specifies addition. If this is not set value, default is 0.
The operating environment of this tutorial: Windows 7 system, python version 3.9, DELL G3 computer.
How to sum in python:
1. Sum usage syntax
sum(iterable[, start])
iterable -- Iterable objects, such as lists, tuples, and sets.
start -- Specify the parameters for addition. If this value is not set, it defaults to 0.
2. Examples of using sum
For example: the result of sum([1,2,3]) is 6
sum((2, 3, 4), 1) The result of
is 10, which means that 1 is added after summing the tuples.
sum([0,1 ,2,3,4], 2) The result of
is 12, which means adding 2 after summing the list.
Related free learning recommendations :python video tutorial
The above is the detailed content of How to sum in python. For more information, please follow other related articles on the PHP Chinese website!