[issue18424] sum() does not return only the sum of a sequence of numbers + PEP8 reccomandation

Marco Buttu report at bugs.python.org
Wed Jul 10 15:11:34 CEST 2013


New submission from Marco Buttu:

The documentaion of sum():

    Returns the sum of a sequence of numbers (NOT strings) plus the 
    value of parameter 'start' (which defaults to 0).  
    When the sequence is empty, returns start.

A. According to the PEP-8 it should be: "Return the sum...", and
   "When the sequence is empty, return start.", like the other docs. 
   For instance:

   >>> print(len.__doc__)
   len(object) -> integer

   Return the number of items of a sequence or mapping.

B. When the second argument is a tuple or a list, you can add sequences
   of sequences:

   >>> sum([['a', 'b', 'c'], [4]], [])
   ['a', 'b', 'c', 4]
   >>> sum(((1, 2, 3), (1,)), (1,))
   (1, 1, 2, 3, 1)

C. sum() takes not just sequences:

   >>> sum({1: 'one', 2: 'two'})
   3

Maybe it is not a good idea to give a complete description of sum() in the docstring, but perhaps something "good enough". In any case, I think the lack of the PEP-8 recommendation should be fixed.

----------
assignee: docs at python
components: Documentation
messages: 192805
nosy: docs at python, marco.buttu
priority: normal
severity: normal
status: open
title: sum() does not return only the sum of a sequence of numbers + PEP8 reccomandation
versions: Python 2.7, Python 3.1, Python 3.2, Python 3.3

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue18424>
_______________________________________


More information about the Python-bugs-list mailing list