List mutation method gotcha - How well known?

John Machin sjmachin at lexicon.net
Thu Mar 13 17:00:49 EDT 2008


On Mar 14, 6:13 am, Arnaud Delobelle <arno... at googlemail.com> wrote:
> On Mar 13, 10:42 am, Paul Rubin <http://phr...@NOSPAM.invalid> wrote:
> [...]
>
> > By Python convention, methods that mutate the object return None, and
> > also stuff that returns None doesn't generate output at the
> > interactive prompt.
>
> A convention that does not always hold:
>
>
>
> >>> l = [1, 2, 3]
> >>> l.pop()
> 3
> >>> l
> [1, 2]

Try this then for the "convention": Any function/method that is not
documented to return something else should be assumed to return None.
Note: no nexus with whether or not the function/method mutates its
args.



More information about the Python-list mailing list