Why do some constructors like int()
, list()
, set()
and many others starts with a lower case letter instead of upper case? Shouldn't this be written Int()
, List()
, Set()
and so on?
These types were original factory functions, not types. As such they got a lower-case name:
$ python1.5
Python 1.5.2 (#1, Apr 1 2009, 22:55:54) [GCC 4.1.2 20070925 (Red Hat
4.1.2-27)] on linux2
Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
>>> type(int)
<type 'builtin_function_or_method'>
That they are now types anyway is a historical artefact
All built-in types now follow this convention, including set
and frozenset
, which were added after the type unification that made int
et al types.
Despite the historical reason for most of these, builtin names that abide to Pythons' naming conventions don't use CapWords. This is specified in PEP 8:
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With