This function is used to calculate the iterable of an iterative object and then add the value of start with this result . The parameter start is used to specify the parameter to add, and if this value is not set, the default value is 0 . The sequence to be computed is generally a numeric type, and the start parameter is set to the number type. In other cases, it is better to use other calculations and methods, such as calculating the string and using the ". Join (sequence),or calculating the floating-point number and using the math.fsum () , or calculate multiple sequences and use itertools.chain ().
Example:
#sum () L = range (Ten) print (l, ' = ', sum (l)) print (sum ([2, 5, 8], 1)) Print (sum ([2, 5, 8], 2)) Print (Sum ((2, 3, 4), 1)) Print (SUM ( Set ([2, 3, 4]), 1))
The resulting output is as follows:
Range (0, 10) = 45
16
17
10
10
Cai Junsheng qq:9073204 Shenzhen
Python standard library: Built-in function sum (iterable[, start])