Katana VentraIP

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]

Paradigm

20 February 1991 (1991-02-20)[2]

3.12.3 Edit this on Wikidata / 9 April 2024 (9 April 2024)

duck, dynamic, strong;[3] optional type annotations (since 3.5, but those hints are ignored, except with unofficial tools)[4]

Tier 1: 64-bit Linux, macOS; 64- and 32-bit Windows 10+[5]
Tier 2: E.g. 32-bit WebAssembly (WASI) Tier 3: 64-bit FreeBSD, iOS; e.g. Raspberry Pi OS
Unofficial (or has been known to work): Other Unix-like/BSD variants and e.g. Android and a few other platforms[6][7][8]

.py, .pyw, .pyz,[9]
.pyi, .pyc, .pyd

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]

Beautiful is better than ugly.

Explicit is better than implicit.

Simple is better than complex.

Complex is better than complicated.

Readability counts.

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,mapandreduce 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]

The statement, using a single equals sign =

assignment

The statement, which conditionally executes a block of code, along with else and elif (a contraction of else-if)

if

The statement, which iterates over an iterable object, capturing each element to a local variable for use by the attached block

for

The statement, which executes a block of code as long as its condition is true

while

The statement, which allows exceptions raised in its attached code block to be caught and handled by except clauses (or new syntax except* in Python 3.11 for exception groups[93]); it also ensures that clean-up code in a finally block is always run regardless of how the block exits

try

The raise statement, used to raise a specified exception or re-raise a caught exception

The class statement, which executes a block of code and attaches its local namespace to a , for use in object-oriented programming

class

The def statement, which defines a or method

function

The statement, which encloses a code block within a context manager (for example, acquiring a lock before it is run, then releasing the lock; or opening and closing a file), allowing resource-acquisition-is-initialization (RAII)-like behavior and replacing a common try/finally idiom[94]

with

The statement, which exits a loop

break

The continue statement, which skips the rest of the current iteration and continues with the next

The del statement, which removes a variable—deleting the reference from the name to the value, and producing an error if the variable is referred to before it is redefined

The pass statement, serving as a , syntactically needed to create an empty code block

NOP

The statement, used in debugging to check for conditions that should apply

assert

The yield statement, which returns a value from a function (and also an operator); used to implement coroutines

generator

The return statement, used to return a value from a function

The and from statements, used to import modules whose functions or variables can be used in the current program

import

is a fast, compliant interpreter of Python 2.7 and 3.8.[142][143] Its just-in-time compiler often brings a significant speed improvement over CPython but some libraries written in C cannot be used with it.[144]

PyPy

is a significant fork of CPython that implements microthreads; it does not use the call stack in the same way, thus allowing massively concurrent programs. PyPy also has a stackless version.[145]

Stackless Python

and CircuitPython are Python 3 variants optimized for microcontrollers, including Lego Mindstorms EV3.[146]

MicroPython

Pyston is a variant of the Python runtime that uses just-in-time compilation to speed up the execution of Python programs.

[147]

Cinder is a performance-oriented fork of CPython 3.8 that contains a number of optimizations, including bytecode inline caching, eager evaluation of coroutines, a method-at-a-time , and an experimental bytecode compiler.[148]

JIT

[149][150][151] Embedded Computing Language (supporting e.g. 8-bit AVR microcontrollers such as ATmega 328P-based Arduino, and larger ones that are MicroPython can also support) "is Python-inspired, but it is not Python. It is possible to write Snek programs that run under a full Python system, but most Python programs will not run under Snek." It's an imperative language not including OOP/classes unlike Python, and simplifying to one number type (like JavaScript, except using smaller) 32-bit single-precision "Integer values of less than 24 bits can be represented exactly in these floating point values".[152]

Snek

Backward-incompatible versions, where code is expected to break and needs to be manually . The first part of the version number is incremented. These releases happen infrequently—version 3.0 was released 8 years after 2.0. According to Guido van Rossum, a version 4.0 is very unlikely to ever happen.[176]

ported

Major or "feature" releases are largely compatible with the previous version but introduce new features. The second part of the version number is incremented. Starting with Python 3.9, these releases are expected to happen annually.[178] Each major version is supported by bug fixes for several years after its release.[179]

[177]

Bugfix releases, which introduce no new features, occur about every 3 months and are made when a sufficient number of bugs have been fixed upstream since the last release. Security vulnerabilities are also patched in these releases. The third and final part of the version number is incremented.[180]

[180]

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.

API documentation generators[edit]

Tools that can generate documentation for Python API include pydoc (available as part of the standard library), Sphinx, Pdoc and its forks, Doxygen and Graphviz, among others.[185]

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]

uses indentation, a similar syntax, and a similar object model.[229]

Boo

uses indentation and a similar syntax, and its Acknowledgements document lists Python first among languages that influenced it.[230]

Cobra

a programming language that cross-compiles to JavaScript, has Python-inspired syntax.

CoffeeScript

JavaScript borrowed iterators and generators from Python.[231]

ECMAScript

a scripting language very similar to Python, built-in to the Godot game engine.[232]

GDScript

is designed for the "speed of working in a dynamic language like Python"[233] and shares the same syntax for slicing arrays.

Go

was motivated by the desire to bring the Python design philosophy to Java.[234]

Groovy

was designed to be "as usable for general programming as Python".[27]

Julia

is a non-strict[28][235] superset of Python (e.g. still missing classes, and adding e.g. struct).[236]

Mojo

uses indentation and similar syntax.[237]

Nim

's creator, Yukihiro Matsumoto, has said: "I wanted a scripting language that was more powerful than Perl, and more object-oriented than Python. That's why I decided to design my own language."[238]

Ruby

a programming language developed by Apple, has some Python-inspired syntax.[239]

Swift

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]

Python syntax and semantics

pip (package manager)

List of programming languages

History of programming languages

Comparison of programming languages

. Python Wiki. 19 July 2012. Archived from the original on 1 November 2012. Retrieved 3 December 2012.

"Python for Artificial Intelligence"

Paine, Jocelyn, ed. (August 2005). . AI Expert Newsletter. Amzi!. Archived from the original on 26 March 2012. Retrieved 11 February 2012.

"AI in Python"

. Pypi.python.org. Retrieved 17 July 2013.

"PyAIML 0.8.5 : Python Package Index"

& Norvig, Peter (2009). Artificial Intelligence: A Modern Approach (3rd ed.). Upper Saddle River, NJ: Prentice Hall. ISBN 978-0-13-604259-4.

Russell, Stuart J.

Downey, Allen B. (May 2012). Think Python: How to Think Like a Computer Scientist (version 1.6.6 ed.). Cambridge University Press.  978-0-521-72596-5.

ISBN

Hamilton, Naomi (5 August 2008). . Computerworld. Archived from the original on 29 December 2008. Retrieved 31 March 2010.

"The A-Z of Programming Languages: Python"

Lutz, Mark (2013). Learning Python (5th ed.). O'Reilly Media.  978-0-596-15806-4.

ISBN

Summerfield, Mark (2009). Programming in Python 3 (2nd ed.). Addison-Wesley Professional.  978-0-321-68056-3.

ISBN

Ramalho, Luciano (May 2022). . O'Reilly Media. ISBN 978-1-4920-5632-4.

Fluent Python

Edit this at Wikidata

Official website