Naming convention for containers in the Python standard library

Viewed 968

Consider the naming convention used for different types of containers in the Python standard library:

Why do some methods follow camel case, but others like deque and defaultdict don't? How are these methods different from each other in a way that would explain this difference?

If it's because at some point the convention changed, why wouldn't the module e.g. provide alias them with camel case names to old names as well?

1 Answers

Usually in python, class names follow the "pascal" case convention, methods / functions follow the "snake" case convention. But here is a official reference from https://www.python.org/dev/peps/pep-0008/:

Package and Module Names

Modules should have short, all-lowercase names. Underscores can be used in the module name if it improves readability. Python packages should also have short, all-lowercase names, although the use of underscores is discouraged.

When an extension module written in C or C++ has an accompanying Python module that provides a higher level (e.g. more object oriented) interface, the C/C++ module has a leading underscore (e.g. _socket).

Class names

Class names should normally use the CapWords convention.

The naming convention for functions may be used instead in cases where the interface is documented and used primarily as a callable.

Note that there is a separate convention for builtin names: most builtin names are single words (or two words run together), with the CapWords convention used only for exception names and builtin constants.

Related