Python (programming language)
Python is a high-level, general-purpose programming language. Its design philosophy emphasizes code readability with the use of significant indentation.[32]
Python is dynamically typed and garbage-collected. It supports multiple programming paradigms, including structured (particularly procedural), object-oriented and functional programming. It is often described as a "batteries included" language due to its comprehensive standard library.[33][34]
Guido van Rossum began working on Python in the late 1980s as a successor to the ABC programming language and first released it in 1991 as Python 0.9.0.[35] Python 2.0 was released in 2000. Python 3.0, released in 2008, was a major revision not completely backward-compatible with earlier versions. Python 2.7.18, released in 2020, was the last release of Python 2.[36]
Python consistently ranks as one of the most popular programming languages, and has gained widespread use in the machine learning community.[37][38][39][40]
Python is a multi-paradigm programming language. Object-oriented programming and structured programming are fully supported, and many of their features support functional programming and aspect-oriented programming (including metaprogramming[66] and metaobjects).[67] Many other paradigms are supported via extensions, including design by contract[68][69] and logic programming.[70]
Python uses dynamic typing and a combination of reference counting and a cycle-detecting garbage collector for memory management.[71] It uses dynamic name resolution (late binding), which binds method and variable names during program execution.
Its design offers some support for functional programming in the Lisp tradition. It has filter
,map
andreduce
functions; list comprehensions, dictionaries, sets, and generator expressions.[72] The standard library has two modules (itertools
and functools
) that implement functional tools borrowed from Haskell and Standard ML.[73]
Its core philosophy is summarized in the Zen of Python (PEP 20), which includes aphorisms such as:[74]
However, Python features regularly violate these principles and received criticism for adding unnecessary language bloat.[75][76] Responses to these criticisms are that the Zen of Python is a guideline rather than a rule.[77] The addition of some new features had been so controversial that Guido van Rossum resigned as Benevolent Dictator for Life following vitriol over the addition of the assignment expression operator in Python 3.8.[78][79]
Nevertheless, rather than building all of its functionality into its core, Python was designed to be highly extensible via modules. This compact modularity has made it particularly popular as a means of adding programmable interfaces to existing applications. Van Rossum's vision of a small core language with a large standard library and easily extensible interpreter stemmed from his frustrations with ABC, which espoused the opposite approach.[41]
Python claims to strive for a simpler, less-cluttered syntax and grammar while giving developers a choice in their coding methodology. In contrast to Perl's "there is more than one way to do it" motto, Python embraces a "there should be one—and preferably only one—obvious way to do it." philosophy.[74] In practice, however, Python provides many ways to achieve the same task. There are, for example, at least three ways to format a string literal, with no certainty as to which one a programmer should use.[80] Alex Martelli, a Fellow at the Python Software Foundation and Python book author, wrote: "To describe something as 'clever' is not considered a compliment in the Python culture."[81]
Python's developers usually strive to avoid premature optimization and reject patches to non-critical parts of the CPython reference implementation that would offer marginal increases in speed at the cost of clarity.[82] Execution speed can be improved by moving speed-critical functions to extension modules written in languages such as C, or by using a just-in-time compiler like PyPy. It is also possible to cross-compile to other languages, but it either doesn't provide the full speed-up that might be expected, since Python is a very dynamic language, or a restricted subset of Python is compiled, and possibly semantics are slightly changed.[83]
Python's developers aim for it to be fun to use. This is reflected in its name—a tribute to the British comedy group Monty Python[84]—and in occasionally playful approaches to tutorials and reference materials, such as the use of the terms "spam" and "eggs" (a reference to a Monty Python sketch) in examples, instead of the often-used "foo" and "bar".[85][86] A common neologism in the Python community is pythonic, which has a wide range of meanings related to program style. "Pythonic" code may use Python idioms well, be natural or show fluency in the language, or conform with Python's minimalist philosophy and emphasis on readability. Code that is difficult to understand or reads like a rough transcription from another programming language is called unpythonic.[87][88]
Python's development is conducted largely through the Python Enhancement Proposal (PEP) process, the primary mechanism for proposing major new features, collecting community input on issues, and documenting Python design decisions.[171] Python coding style is covered in PEP 8.[172] Outstanding PEPs are reviewed and commented on by the Python community and the steering council.[171]
Enhancement of the language corresponds with the development of the CPython reference implementation. The mailing list python-dev is the primary forum for the language's development. Specific issues were originally discussed in the Roundup bug tracker hosted at by the foundation.[173] In 2022, all issues and discussions were migrated to GitHub.[174] Development originally took place on a self-hosted source-code repository running Mercurial, until Python moved to GitHub in January 2017.[175]
CPython's public releases come in three types, distinguished by which part of the version number is incremented:
Many alpha, beta, and release-candidates are also released as previews and for testing before final releases. Although there is a rough schedule for each release, they are often delayed if the code is not ready. Python's development team monitors the state of the code by running the large unit test suite during development.[181]
The major academic conference on Python is PyCon. There are also special Python mentoring programs, such as PyLadies.
Python 3.12 removed wstr
meaning Python extensions[182] need to be modified,[183] and 3.10 added pattern matching to the language.[184]
Python 3.12 dropped some outdated modules, and more will be dropped in the future, deprecated as of 3.13; already deprecated array 'u' format code will emit DeprecationWarning
since 3.13 and will be removed in Python 3.16. The 'w' format code should be used instead. Part of ctypes is also deprecated and http.server.CGIHTTPRequestHandler
will emit a DeprecationWarning, and will be removed in 3.15. Using that code already has a high potential for both security and functionality bugs. Parts of the typing module are deprecated, e.g. creating a typing.NamedTuple
class using keyword arguments to denote the fields and such (and more) will be disallowed in Python 3.15.
Naming[edit]
Python's name is derived from the British comedy group Monty Python, whom Python creator Guido van Rossum enjoyed while developing the language. Monty Python references appear frequently in Python code and culture;[186] for example, the metasyntactic variables often used in Python literature are spam and eggs instead of the traditional foo and bar.[186][187] The official Python documentation also contains various references to Monty Python routines.[188][189] Users of Python are sometimes referred to as "Pythonistas".[190]
The prefix Py- is used to show that something is related to Python. Examples of the use of this prefix in names of Python applications or libraries include Pygame, a binding of SDL to Python (commonly used to create games); PyQt and PyGTK, which bind Qt and GTK to Python respectively; and PyPy, a Python implementation originally written in Python.
Popularity[edit]
Since 2003, Python has consistently ranked in the top ten most popular programming languages in the TIOBE Programming Community Index where as of December 2022 it was the most popular language (ahead of C, C++, and Java).[39] It was selected as Programming Language of the Year (for "the highest rise in ratings in a year") in 2007, 2010, 2018, and 2020 (the only language to have done so four times as of 2020[191]).
Large organizations that use Python include Wikipedia, Google,[192] Yahoo!,[193] CERN,[194] NASA,[195] Facebook,[196] Amazon, Instagram,[197] Spotify,[198] and some smaller entities like ILM[199] and ITA.[200] The social news networking site Reddit was written mostly in Python.[201]
Python's design and philosophy have influenced many other programming languages:
Python's development practices have also been emulated by other languages. For example, the practice of requiring a document describing the rationale for, and issues surrounding, a change to the language (in Python, a PEP) is also used in Tcl,[240] Erlang,[241] and Swift.[242]