Why do some built-in constructors start with a lowercase letter?

Why do some constructors, such as int() , list() , set() and many others, start with a lowercase letter instead of uppercase? Shouldn't it be written int() , list() , set() , etc.?

+5
source share
2 answers

These types were original factory functions, not types. So they got a lower 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'> 

The fact that they are now types is a historical artifact anyway

All built-in types now follow this convention, including set and frozenset , which were added after the unification of the types that the types int et al.

+5
source

Despite the historical reason for most of them, built-in names that comply with the Python naming conventions do not use CapWords. This is stated in PEP 8 :

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

+6
source

Source: https://habr.com/ru/post/1268646/


All Articles