Different "look and feel" of some built-in functions

Chris Angelico rosuav at gmail.com
Sat Sep 25 12:38:30 EDT 2021


On Sun, Sep 26, 2021 at 2:27 AM Dieter Maurer <dieter at handshake.de> wrote:
>
> Stefan Ram wrote at 2021-9-24 16:48 GMT:
> >"Dieter Maurer" <dieter at handshake.de> writes:
> >>A list is ordered. Therefore, it is important where
> >>in this order an element is added. Thus, for a list,
> >>`append` is a better name than `add` -- because it already
> >>tells us in the name where it adds the new element.
> >
> >  In a collection of texts, which is not large but mixed from
> >  many different fields and genres, I find (using a Python
> >  script, of course) eight hits for "added to the list" :
> >
> >|s and rock n roll can be added to the list. As - Taylor, 2012
> >| of opinion was probably added to the list tow - from a dictionary
> >|gg and his wife might be added to the list of  - Sir Walter Scott
> >|ships when your name was added to the list. In - Percy Bysshe Shelley
> >|em that wealth should be added to the list. No - Henry
> >|n was discovered and was added to the list of  - from a dictionary
> >|nd said his name must be added to the list, or - Mark Twain
>
> While a list is ordered,
> applications using a list may not be interested in the particular
> order and thus just speak of "add to the list"
> rather than "append to the list".
>
> Nevertheless, I find the name `append` far better than `add` for
> the list type - because it describes better what it is doing.
> I am a big fan of "speaking names".

Yeah, so I would say it makes perfectly good sense to do something like this:

def add_customer(...):
    cust = ...
    customers.append(cust)

where it's "add" in your application, but "append" in Python's list object.

ChrisA


More information about the Python-list mailing list