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

Dieter Maurer dieter at handshake.de
Fri Sep 24 12:18:00 EDT 2021


Stefan Ram wrote at 2021-9-24 14:53 GMT:
>Steve Keller <keller.steve at gmx.de> writes:
>>Why do some built-in Python functions feel so differently:
>
>|>>> s = set()
>|>>> s.add( 1 )
>|>>>
>
>
>|>>> l = []
>|>>> l.add( 1 )
>
>|
>|Traceback (most recent call last):
>|  File "<stdin>", line 1, in <module>
>|AttributeError: 'list' object has no attribute 'add'
>|
>|>>> l.append( 1 )

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.

A set is unordered. Therefore, the name `append` does not make sense
for a set.



--
Dieter


More information about the Python-list mailing list