Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why do some built-in constructors begin with a lower case letter?

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?

like image 550
flpn Avatar asked Jun 07 '17 21:06

flpn


2 Answers

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.

like image 91
Martijn Pieters Avatar answered Nov 09 '22 03:11

Martijn Pieters


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.

like image 29
Dimitris Fasarakis Hilliard Avatar answered Nov 09 '22 03:11

Dimitris Fasarakis Hilliard