Issue36491
Created on 2019-03-31 06:09 by Camion, last changed 2022-04-11 14:59 by admin. This issue is now closed.
| Messages (4) | |||
|---|---|---|---|
| msg339245 - (view) | Author: (Camion) | Date: 2019-03-31 06:09 | |
>>> help(sum)
Help on built-in function sum in module builtins:
sum(iterable, start=0, /)
Return the sum of a 'start' value (default: 0) plus an iterable of numbers
When the iterable is empty, return the start value.
This function is intended specifically for use with numeric values and may
reject non-numeric types.
>>> sum([1, 2, 3], start=3)
Traceback (most recent call last):
File "<pyshell#11>", line 1, in <module>
sum([1, 2, 3], start=3)
TypeError: sum() takes no keyword arguments
By the way, it is very annoying that the start value is not available, because it hampers the possibility to use sum with things like vectors.
|
|||
| msg339246 - (view) | Author: Stefan Behnel (scoder) * ![]() |
Date: 2019-03-31 06:14 | |
It's currently implemented as a positional argument, not a keyword argument. Thus the "/" at the end of the signature in the help text. That also suggests that it was a conscious decision, not an oversight. Personally, I'd also prefer it if it was available as a keyword argument. |
|||
| msg339247 - (view) | Author: Karthikeyan Singaravelan (xtreak) * ![]() |
Date: 2019-03-31 06:18 | |
Is this about sum not accepting start as keyword argument? It's fixed with issue34637. The help function in the report is that start could only be a positional argument with start appearing before '/' in "sum(iterable, start=0, /)" . This has been changed in 3.8 to below signature. sum(iterable, /, start=0) Return the sum of a 'start' value (default: 0) plus an iterable of numbers When the iterable is empty, return the start value. This function is intended specifically for use with numeric values and may reject non-numeric types. $ python3.7 Python 3.7.1rc2 (v3.7.1rc2:6c06ef7dc3, Oct 13 2018, 05:10:29) [Clang 6.0 (clang-600.0.57)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> sum(range(10), start=10) Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: sum() takes no keyword arguments # 3.8 $ ./python.exe Python 3.8.0a3+ (heads/master:7444daada1, Mar 30 2019, 20:27:47) [Clang 7.0.2 (clang-700.1.81)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> sum(range(10), start=10) 55 |
|||
| msg339248 - (view) | Author: Stefan Behnel (scoder) * ![]() |
Date: 2019-03-31 06:22 | |
Yes, duplicate of issue34637. |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022-04-11 14:59:13 | admin | set | github: 80672 |
| 2019-03-31 06:28:59 | xtreak | set | superseder: Make *start* usable as a keyword argument for sum(). |
| 2019-03-31 06:26:40 | rhettinger | set | status: open -> closed resolution: duplicate stage: resolved |
| 2019-03-31 06:22:22 | scoder | set | messages: + msg339248 |
| 2019-03-31 06:18:04 | xtreak | set | nosy:
+ rhettinger, xtreak messages: + msg339247 |
| 2019-03-31 06:14:43 | scoder | set | nosy:
+ scoder messages: + msg339246 |
| 2019-03-31 06:09:17 | Camion | create | |
