A function introduced .sum
python sum as a function of built-in functions, by definition, can find the sum of all elements in the iterator syntax is as follows:
sum(iterable,start=0)
Parameter Description:
iterable - iterables, such as: a list, tuple set;
start - adding the specified parameters, if this value is not set, the default is 0;
Return Value - returns an iterator sum obtained by adding all of the elements;
Function uses two .sum
# ! Usr / bin / env Python # - * - Coding: UTF-8 _ * - "" " @author: Why grief @Blog (personal blog address): shuopython.com @WeChat Official the Account (micro-channel public number): Ape said Python @Github: www.github.com @file: python_sum.py @time: 2019/12/11 21:25 @Motto: short step a thousand miles, no small streams into a mighty torrent, wonderful life program need to accumulate persistently! "" " Print (SUM ([0,1,2])) # equivalent +. 1 + 2 = 0. 3 Print (SUM ((0,1,2), 10)) # equivalent 1 + 2 + 0 + 10 = 13 is Print (SUM ([0,1,2], 20)) # is equivalent to 0 + 1 + 2 + 20 = 23
Output:
3 13 23
you may also like:
1.python file read and write open / write / readline / close
3.python exception handling try except
4.python thread creation and parameter passing
Reproduced please specify: ape say Python » Python SUM function
Technical exchanges, business cooperation please contact bloggers
Scan code or search: ape say python
Ape say python
No. sweep the micro-channel public concern