Reputation: 1978
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?
Upvotes: 9
Views: 238
Reputation: 1122482
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.
Upvotes: 9
Reputation: 160477
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.
Upvotes: 7