Skip to content
Surf Wiki
Save to docs
technology/programming-languages

From Surf Wiki (app.surf) — the open knowledge base

Python (programming language)

General-purpose programming language


General-purpose programming language

FieldValue
logoPython-logo-notext.svg
logo size150px
paradigmMulti-paradigm: object-oriented, procedural (imperative), functional, structured, reflective
released
designerGuido van Rossum
developerPython Software Foundation
latest release version
latest release date
latest preview version
latest preview date
{{#invoke:WikidataqualifierP348P577qualifierP548:Q51930650rank = bestformatting = date }}
typingDuck, dynamic, strong; optional type annotations
memory managementGarbage-collected
implementationsCPython, PyPy, MicroPython, CircuitPython, IronPython, Jython, Stackless Python
operating systemCross-platform
{{efn* Tier 1: 64-bit Linux, macOS; 64- and 32-bit Windows<!-- Windows 8.1 supported with 3.10 to 3.13 but only Windows 10+ with latest Python 3.14+--><ref>{{Cite weblast1von Löwisfirst1=Martinlast2=Cannonfirst2=Bretttitle=PEP 11 – CPython platform supporturl=https://peps.python.org/pep-0011/access-date=22 April 2024website=Python Enhancement Proposals (PEPs)language=en}}
* Tier 3: 64-bit Android<!-- too much trivia to mention "5.0+", even if true, it seemingly is, and corresponding API levels, but thouse are ancient, possibly even only way more recent is officially supported? -->,<ref>{{Cite webtitlePEP 738 – Adding Android as a supported platform peps.python.orgurl=https://peps.python.org/pep-0738/access-date=19 May 2024website=Python Enhancement Proposals (PEPs)language=en}} iOS, FreeBSD, and (32-bit) Raspberry Pi OS
Unofficial (or has been known to work): Other Unix-like/BSD variants) and a few other platforms}}
-->licensePython Software Foundation License
file ext.py, .pyw, .pyz,
.pyi, .pyc, .pyd<!-- too much trivia: .pyo (before 3.5)<ref>File extension .pyo was removed in Python 3.5. See [https://www.python.org/dev/peps/pep-0488/ PEP 0488] {{Webarchiveurlhttps://web.archive.org/web/20200601133202/https://www.python.org/dev/peps/pep-0488/date=1 June 2020}} --
website
dialectsCython, RPython, Starlark
influenced byABC, Ada, ALGOL 68, APL, C, [C++](c), CLU, Dylan, Haskell, Icon, Lisp, Modula-3, Perl, Standard ML
influencedApache Groovy, Boo, Cobra, CoffeeScript, D, F#, GDScript, Go, JavaScript, Julia, Mojo, Nim, Ruby, Swift, V
<!-- Do not put in as there's a pure Java implementation (Jython):programming languageC --wikibooks = Python Programming

--

"Windows 8 and newer for Python 3.9 FreeBSD 10 and newer macOS Snow Leopard (macOS 10.6, 2008) and newer"

  • Tier 2: E.g. 32-bit WebAssembly (WASI)
  • Tier 3: 64-bit Android, iOS, FreeBSD, and (32-bit) Raspberry Pi OS Unofficial (or has been known to work): Other Unix-like/BSD variants) and a few other platforms}}

https://mail.python.org/archives/list/python-committers@python.org/thread/K757345KX6W5ZLTWYBUXOXQTJJTL7GW5/

  • Alpine / musl is not supported, because our test suite is failing due to bugs and missing features in musl libc.
  • NetBSD and OpenBSD are in a similar state as Alpine: no stable buildbot and AFAIK tests are failing
  • [outdated]
  • Cygwin and MinGW are officially unsupported, see bpo-45537 and bpo-45538

..

The policy Brett is proposing just makes that explicit and gives us something to point to when someone comes up with a patch to support PDP-11 or when someone's patch for Android breaks Windows. I don't think we'll wind up with tier support police; if a core dev wants to take responsibility for a patch for a platform that is not tier 3 or above they can still do that, but if it breaks things for a supported platform it will be reverted.

..

E.g. Android support was even funded by the PSF recently.[outdated] Also, note that the stdlib does in fact support other Python implementations reusing (parts of) it, e.g. Jython, PyPy and IronPython. Again, without core devs backing these. --| license = Python Software Foundation License

.pyi, .pyc, .pyd

Python is a high-level, general-purpose programming language. Its design philosophy emphasizes code readability with the use of significant indentation. Python is dynamically type-checked and garbage-collected. It supports multiple programming paradigms, including structured (particularly procedural), object-oriented and functional programming.

Guido van Rossum began working on Python in the late 1980s as a successor to the ABC programming language. Python 3.0, released in 2008, was a major revision and not completely backward-compatible with earlier versions. Beginning with Python 3.5, capabilities and keywords for typing were added to the language, allowing optional static typing. , the Python Software Foundation supports Python 3.10, 3.11, 3.12, 3.13, and 3.14, following the project's annual release cycle and five-year support policy. Python 3.15 is currently in the alpha development phase, and the stable release is expected to come out in October 2026."Earlier versions in the 3.x series have reached end-of-life and no longer receive security updates.

Python has gained widespread use in the machine learning community. It is widely taught as an introductory programming language. Since 2003, Python has consistently ranked in the top ten of the most popular programming languages in the TIOBE Programming Community Index, which ranks based on searches in 24 platforms.

History

Main article: History of Python

Python was conceived in the late 1980s by Guido van Rossum at Centrum Wiskunde & Informatica (CWI) in the Netherlands. It was designed as a successor to the ABC programming language, which was inspired by SETL, capable of exception handling and interfacing with the Amoeba operating system. Python implementation began in December 1989. Van Rossum first released it in 1991 as Python 0.9.0. Van Rossum assumed sole responsibility for the project, as the lead developer, until 12 July 2018, when he announced his "permanent vacation" from responsibilities as Python's "benevolent dictator for life" (BDFL); this title was bestowed on him by the Python community to reflect his long-term commitment as the project's chief decision-maker. (He has since come out of retirement and is self-titled "BDFL-emeritus".) In January 2019, active Python core developers elected a five-member Steering Council to lead the project.

The name Python derives from the British comedy series Monty Python's Flying Circus. (See .)

Python 2.0 was released on 16 October 2000, featuring many new features such as list comprehensions, cycle-detecting garbage collection, reference counting, and Unicode support. Python 2.7's end-of-life was initially set for 2015, and then postponed to 2020 out of concern that a large body of existing code could not easily be forward-ported to Python 3. It no longer receives security patches or updates. While Python 2.7 and older versions are officially unsupported, a different unofficial Python implementation, PyPy, continues to support Python 2, i.e., "2.7.18+" (plus 3.11), with the plus signifying (at least some) "backported security updates".

Python 3.0 was released on 3 December 2008, and was a major revision and not completely backward-compatible with earlier versions, with some new semantics and changed syntax. Python 2.7.18, released in 2020, was the last release of Python 2. Several releases in the Python 3.x series have added new syntax to the language, and made a few (considered very minor) backward-incompatible changes.

, Python is the latest stable release. All older 3.x versions had a security update down to Python 3.9.24 then again with 3.9.25, the final version in 3.9 series. Python 3.10 is, since November 2025, the oldest supported branch. Python 3.15 has an alpha released, and Android has an official downloadable executable available for Python 3.14. Releases receive two years of full support followed by three years of security support.

Design philosophy and features

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 because it is purposely designed to be able to integrate components written in other languages.

Python uses dynamic typing and a combination of reference counting and a cycle-detecting garbage collector for memory management. It uses dynamic name resolution (late binding), which binds method and variable names during program execution.

Python's design offers some support for functional programming in the "Lisp tradition". It has , , and functions; list comprehensions, dictionaries, sets, and generator expressions. The standard library has two modules ( and ) that implement functional tools borrowed from Haskell and Standard ML.

Python's core philosophy is summarized in the Zen of Python (PEP 20) written by Tim Peters, which includes aphorisms such as these:

  • Explicit is better than implicit.
  • Simple is better than complex.
  • Readability counts.
  • Special cases aren't special enough to break the rules.
  • Although practicality beats purity, errors should never pass silently, unless explicitly silenced.
  • There should be one-- and preferably only one --obvious way to do it.

However, Python has received criticism for violating these principles and adding unnecessary language bloat. Responses to these criticisms note that the Zen of Python is a guideline rather than a rule. The addition of some new features had been controversial: Guido van Rossum resigned as Benevolent Dictator for Life after conflict about adding the assignment expression operator in

Nevertheless, rather than building all 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 represented the opposite approach.

Python claims to strive for a simpler, less-cluttered syntax and grammar, while giving developers a choice in their coding methodology. Python lacks do .. while loops, which Rossum considered harmful. In contrast to Perl's motto "there is more than one way to do it", Python advocates an approach where "there should be one – and preferably only one – obvious way to do it". Alex Martelli is a Fellow at the Python Software Foundation and Python book author; he wrote that "To describe something as 'clever' is not considered a compliment in the Python culture."

Python's developers typically prioritize readability over performance. For example, they reject patches to non-critical parts of the CPython reference implementation that would offer increases in speed that do not justify the cost of clarity and readability. 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. Also, it is possible to transpile to other languages. However, this approach either fails to achieve the expected speed-up, since Python is a very dynamic language, or only a restricted subset of Python is compiled (with potential minor semantic changes).

Python is meant to be a fun language to use. This goal is reflected in the name – a tribute to the British comedy group Monty Python

A common neologism in the Python community is pythonic, which has a broad 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.

Syntax and semantics

Main article: Python syntax and semantics

Python is meant to be an easily readable language. Its formatting is visually uncluttered and often uses English keywords where other languages use punctuation. Unlike many other languages, it does not use curly brackets to delimit blocks, and semicolons after statements are allowed but rarely used. It has fewer syntactic exceptions and special cases than C or Pascal.

Indentation

Python uses whitespace indentation, rather than curly brackets or keywords, to delimit blocks. An increase in indentation comes after certain statements; a decrease in indentation signifies the end of the current block. Thus, the program's visual structure accurately represents its semantic structure. This feature is sometimes termed the off-side rule. Some other languages use indentation this way; but in most, indentation has no semantic meaning. The recommended indent size is four spaces.

Statements and control flow

Python's statements include the following:

  • The assignment statement, using a single equals sign =
  • The if statement, which conditionally executes a block of code, along with else and elif (a contraction of else if)
  • The for statement, which iterates over an iterable object, capturing each element to a variable for use by the attached block; the variable is not deleted when the loop finishes
  • The while statement, which executes a block of code as long as boolean condition is true
  • The try 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); the try statement also ensures that clean-up code in a finally block is always run regardless of how the block exits
  • 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 class, for use in object-oriented programming
  • The def statement, which defines a function or method
  • The with statement, which encloses a code block within a context manager, allowing resource-acquisition-is-initialization (RAII)-like behavior and replacing a common try/finally idiom Examples of a context include acquiring a lock before some code is run, and then releasing the lock; or opening and then closing a file
  • The break statement, which exits a loop
  • 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 NOP (i.e., no operation), which is syntactically needed to create an empty code block
  • The assert statement, used in debugging to check for conditions that should apply
  • The yield statement, which returns a value from a generator function (and also an operator); used to implement coroutines
  • The return statement, used to return a value from a function
  • The import and from statements, used to import modules whose functions or variables can be used in the current program
  • The match and case statements, analogous to a switch statement construct, which compares an expression against one or more cases as a control-flow measure

The assignment statement (=) binds a name as a reference to a separate, dynamically allocated object. Variables may subsequently be rebound at any time to any object. In Python, a variable name is a generic reference holder without a fixed data type; however, it always refers to some object with a type. This is called dynamic typing—in contrast to statically-typed languages, where each variable may contain only a value of a certain type.

Python does not support tail call optimization or first-class continuations; according to Van Rossum, the language never will. However, better support for coroutine-like functionality is provided by extending Python's generators. Before 2.5, generators were lazy iterators; data was passed unidirectionally out of the generator. From Python 2.5 on, it is possible to pass data back into a generator function; and from version 3.3, data can be passed through multiple stack levels.

Expressions

Python's expressions include the following:

  • The +, -, and * operators for mathematical addition, subtraction, and multiplication are similar to other languages, but the behavior of division differs. There are two types of division in Python: floor division (or integer division) //, and floating-point division /. Python uses the ** operator for exponentiation.
  • Python uses the + operator for string concatenation. The language uses the * operator for duplicating a string a specified number of times.
  • The @ infix operator is intended to be used by libraries such as NumPy for matrix multiplication.
  • The syntax :=, called the "", was introduced in Python 3.8. This operator assigns values to variables as part of a larger expression.
  • In Python, == compares two objects by value. Python's is operator may be used to compare object identities (i.e., comparison by reference), and comparisons may be chained—for example, {{code|lang=python|code=a
  • Python uses and, or, and not as Boolean operators.
  • Python has a type of expression called a list comprehension, and a more general expression called a generator expression.
  • Anonymous functions are implemented using lambda expressions; however, there may be only one expression in each body.
  • Conditional expressions are written as . (This is different in operand order from the [c ? x : y]() operator common to many other languages.)
  • Python makes a distinction between lists and tuples. Lists are written as , are mutable, and cannot be used as the keys of dictionaries (since dictionary keys must be immutable in Python). Tuples, written as , are immutable and thus can be used as the keys of dictionaries, provided that all of the tuple's elements are immutable. The + operator can be used to concatenate two tuples, which does not directly modify their contents, but produces a new tuple containing the elements of both. For example, given the variable t initially equal to , executing first evaluates , which yields ; this result is then assigned back to t—thereby effectively "modifying the contents" of t while conforming to the immutable nature of tuple objects. Parentheses are optional for tuples in unambiguous contexts.
  • Python features sequence unpacking where multiple expressions, each evaluating to something assignable (e.g., a variable or a writable property) are associated just as in forming tuple literal; as a whole, the results are then put on the left-hand side of the equal sign in an assignment statement. This statement expects an iterable object on the right-hand side of the equal sign to produce the same number of values as the writable expressions on the left-hand side; while iterating, the statement assigns each of the values produced on the right to the corresponding expression on the left.
  • Python has a "string format" operator % that functions analogously to printf format strings in the C language—e.g. evaluates to "spam=blah eggs=2". In Python 2.6+ and 3+, this operator was supplemented by the format() method of the str class, e.g., . Python 3.6 added "f-strings": .
  • Strings in Python can be concatenated by "adding" them (using the same operator as for adding integers and floats); e.g., returns "spameggs". If strings contain numbers, they are concatenated as strings rather than as integers, e.g. returns "22".
  • Python supports string literals in several ways:
    • Delimited by single or double quotation marks; single and double quotation marks have equivalent functionality (unlike in Unix shells, Perl, and Perl-influenced languages). Both marks use the backslash (\) as an escape character. String interpolation became available in Python 3.6 as "formatted string literals".
    • Triple-quoted, i.e., starting and ending with three single or double quotation marks; this may span multiple lines and function like here documents in shells, Perl, and Ruby.
    • Raw string varieties, denoted by prefixing the string literal with r. Escape sequences are not interpreted; hence raw strings are useful where literal backslashes are common, such as in regular expressions and Windows-style paths. (Compare "@-quoting" in C#.)
  • Python has array index and array slicing expressions in lists, which are written as a[key], or . Indexes are zero-based, and negative indexes are relative to the end. Slices take elements from the start index up to, but not including, the stop index. The (optional) third slice parameter, called step or stride, allows elements to be skipped or reversed. Slice indexes may be omitted—for example, returns a copy of the entire list. Each element of a slice is a shallow copy.

In Python, a distinction between expressions and statements is rigidly enforced, in contrast to languages such as Common Lisp, Scheme, or Ruby. This distinction leads to duplicating some functionality, for example:

  • List comprehensions vs. for-loops
  • Conditional expressions vs. if blocks
  • The eval() vs. exec() built-in functions (in Python 2, exec is a statement); the former function is for expressions, while the latter is for statements

A statement cannot be part of an expression; because of this restriction, expressions such as list and dict comprehensions (and lambda expressions) cannot contain statements. As a particular case, an assignment statement such as cannot be part of the conditional expression of a conditional statement.

Typing

The standard type hierarchy in Python&nbsp;3

Python uses duck typing, and it has typed objects but untyped variable names. Type constraints are not checked at definition time; rather, operations on an object may fail at usage time, indicating that the object is not of an appropriate type. Despite being dynamically typed, Python is strongly typed, forbidding operations that are poorly defined (e.g., adding a number and a string) rather than quietly attempting to interpret them.

Python allows programmers to define their own types using classes, most often for object-oriented programming. New instances of classes are constructed by calling the class, for example, or ); the classes are instances of the metaclass type (which is an instance of itself), thereby allowing metaprogramming and reflection.

Before version 3.0, Python had two kinds of classes, both using the same syntax: old-style and new-style. Current Python versions support the semantics of only the new style.

Python supports optional type annotations. These annotations are not enforced by the language, but may be used by external tools such as mypy to catch errors. Python includes a module typing including several type names for type annotations. Also, mypy supports a Python compiler called mypyc, which leverages type annotations for optimization.

TypeMutabilityDescriptionSyntax examples
`bool`immutableBoolean value
`bytearray`mutableSequence of bytes
`bytes`immutableSequence of bytes
`complex`immutableComplex number with real and imaginary parts
`dict`mutableAssociative array (or dictionary) of key and value pairs; can contain mixed types (keys and values); keys must be a hashable type
`types.EllipsisType`immutableAn ellipsis placeholder to be used as an index in NumPy arrays
`float`immutableDouble-precision floating-point number. The precision is machine-dependent, but in practice it is generally implemented as a 64-bit IEEE 754 number with 53 bits of precision.{{Cite webtitle=15. Floating Point Arithmetic: Issues and Limitations – Python 3.8.3 documentation
`frozenset`immutableUnordered set, contains no duplicates; can contain mixed types, if hashable
`int`immutableInteger of unlimited magnitude
`list`mutableList, can contain mixed types
`types.NoneType`immutableAn object representing the absence of a value, often called null in other languages
`types.NotImplementedType`immutableA placeholder that can be returned from overloaded operators to indicate unsupported operand types.
`range`immutableAn *immutable sequence* of numbers, commonly used for iterating a specific number of times in `for` loops
`set`mutableUnordered set, contains no duplicates; can contain mixed types, if hashable
`str`immutableA character string: sequence of Unicode codepoints
"""Spanning
`tuple`immutableTuple, can contain mixed types

Arithmetic operations

Python includes conventional symbols for arithmetic operators (+, -, *, /), the floor-division operator //, and the modulo operator %. (With the modulo operator, a remainder can be negative, e.g., 4 % -3 == -2.) Also, Python offers the ** symbol for exponentiation, e.g. 5**3 == 125 and 9**0.5 == 3.0. Also, it offers the matrix‑multiplication operator @ . These operators work as in traditional mathematics; with the same precedence rules, the infix operators + and - can also be unary, to represent positive and negative numbers respectively.

Division between integers produces floating-point results. The behavior of division has changed significantly over time:

  • The current version of Python (i.e., since 3.0) changed the / operator to always represent floating-point division, e.g., .
  • The floor division // operator was introduced, meaning that 7//3 == 2, -7//3 == -3, 7.5//3 == 2.0, and -7.5//3 == -3.0. For Python 2.7, adding the statement allows a module in Python 2.7 to use Python 3.x rules for division (see above).

In Python terms, the / operator represents true division (or simply division), while the // operator represents floor division. Before version 3.0, the / operator represents classic division.

Rounding towards negative infinity, though a different method than in most languages, adds consistency to Python. For instance, this rounding implies that the equation is always true. Also, the rounding implies that the equation is valid for both positive and negative values of a. As expected, the result of a%b lies in the half-open interval [0, b), where b is a positive integer; however, maintaining the validity of the equation requires that the result must lie in the interval (b, 0] when b is negative.

Python provides a round function for rounding a float to the nearest integer. For tie-breaking, Python 3 uses the round to even method: round(1.5) and round(2.5) both produce 2. Python versions before 3 used the round-away-from-zero method: round(0.5) is 1.0, and round(-0.5) is −1.0.

Python allows Boolean expressions that contain multiple equality relations to be consistent with general usage in mathematics. For example, the expression `a

Python uses arbitrary-precision arithmetic for all integer operations. The Decimal type/class in the decimal module provides decimal floating-point numbers to a pre-defined arbitrary precision with several rounding modes. The Fraction class in the fractions module provides arbitrary precision for rational numbers.

Due to Python's extensive mathematics library and the third-party library NumPy, the language is frequently used for scientific scripting in tasks such as numerical data processing and manipulation.

Function syntax

Functions are created in Python by using the def keyword. A function is defined similarly to how it is called, by first providing the function name and then the required parameters. Here is an example of a function that prints its inputs:

def printer(input1, input2 = "already there"):
    print(input1)
    print(input2)
    
printer("hello")
    
# Example output:
# hello
# already there
To assign a default value to a function parameter in case no actual value is provided at run time, variable-definition syntax can be used inside the function header.

Code examples

"Hello, World!" program:

print('Hello, World!')

Program to calculate the factorial of a non-negative integer:

text = input('Type a number, and its factorial will be printed: ')
n = int(text)

if n < 0:
    raise ValueError('You must enter a non-negative integer')

factorial = 1
for i in range(2, n + 1):
    factorial *= i

print(factorial)

<!--

Please don't add more examples.

--

Libraries

Python's large standard library is commonly cited as one of its greatest strengths. For Internet-facing applications, many standard formats and protocols such as MIME and HTTP are supported. The language includes modules for creating graphical user interfaces, connecting to relational databases, generating pseudorandom numbers, arithmetic with arbitrary-precision decimals, manipulating regular expressions, and unit testing.

Some parts of the standard library are covered by specifications—for example, the Web Server Gateway Interface (WSGI) implementation wsgiref follows PEP 333—but most parts are specified by their code, internal documentation, and test suites. However, because most of the standard library is cross-platform Python code, only a few modules must be altered or rewritten for variant implementations.

the Python Package Index (PyPI), the official repository for third-party Python software, contains over 614,339 packages.

Development environments

Most Python implementations (including CPython) include a read–eval–print loop (REPL); this permits the environment to function as a command line interpreter, with which users enter statements sequentially and receive results immediately.

Also, CPython is bundled with an integrated development environment (IDE) called IDLE, which is oriented toward beginners.

Other shells, including IDLE and IPython, add additional capabilities such as improved auto-completion, session-state retention, and syntax highlighting.

Standard desktop IDEs include PyCharm, Spyder, and Visual Studio Code; there are web browser-based IDEs, such as the following environments:

  • Jupyter Notebooks, an open-source interactive computing platform;
  • PythonAnywhere, a browser-based IDE and hosting environment; and
  • Canopy, a commercial IDE from Enthought that emphasizes scientific computing.

Implementations

Reference implementation

CPython is the reference implementation of Python. This implementation is written in C, meeting the C11 standard since version 3.11. Older versions use the C89 standard with several select C99 features, but third-party extensions are not limited to older C versions—e.g., they can be implemented using C11 or C++. CPython compiles Python programs into an intermediate bytecode, which is then executed by a virtual machine. CPython is distributed with a large standard library written in a combination of C and native Python.

CPython is available for many platforms, including Windows and most modern Unix-like systems, including macOS (and Apple M1 Macs, since Python 3.9.1, using an experimental installer). Starting with Python 3.9, the Python installer intentionally fails to install on Windows 7 and 8; Windows XP was supported until Python 3.5, with unofficial support for VMS. Platform portability was one of Python's earliest priorities. During development of Python 1 and 2, even OS/2 and Solaris were supported; since that time, support has been dropped for many platforms.

Starting with CPython 3.7.0, *nix platforms are expected to provide at least one of C.UTF-8 (full locale), C.utf8 (full locale) or UTF-8 (LC_CTYPE-only locale) as an alternative to the legacy C locale.

All current Python versions (since 3.7) support only operating systems that feature multithreading, by now supporting not nearly as many operating systems (dropping many outdated) than in the past.

Limitations of the reference implementation

  • The energy usage of Python with CPython for typically written code is much worse than C by a factor of 75.88.
  • The throughput of Python with CPython for typically written code is worse than C by a factor of 71.9.
  • The average memory usage of CPython for typically written code is worse than C by a factor of 2.4.

Other implementations

All alternative implementations have at least slightly different semantics. For example, an alternative may include unordered dictionaries, in contrast to other current Python versions. As another example in the larger Python ecosystem, PyPy does not support the full C Python API.

Creating an executable with Python often is done by bundling an entire Python interpreter into the executable, which causes binary sizes to be massive for small programs, yet there exist implementations that are capable of truly compiling Python. Alternative implementations include the following:

  • PyPy is a faster, compliant interpreter of Python 2.7 and 3.10. PyPy's just-in-time compiler often improves speed significantly relative to CPython, but PyPy does not support some libraries written in C. PyPy offers support for the RISC-V instruction-set architecture.
  • Codon is an implementation with an ahead-of-time (AOT) compiler, which compiles a statically-typed Python-like language whose "syntax and semantics are nearly identical to Python's, there are some notable differences" For example, Codon uses 64-bit machine integers for speed, not arbitrarily as with Python; Codon developers claim that speedups over CPython are usually on the order of ten to a hundred times. Codon compiles to machine code (via LLVM) and supports native multithreading. Codon can also compile to Python extension modules that can be imported and used from Python.
  • MicroPython and CircuitPython are Python 3 variants that are optimized for microcontrollers, including the Lego Mindstorms EV3.
  • Pyston is a variant of the Python runtime that uses just-in-time compilation to speed up execution of Python programs.
  • Cinder is a performance-oriented fork of CPython 3.8 that features a number of optimizations, including bytecode inline caching, eager evaluation of coroutines, a method-at-a-time JIT, and an experimental bytecode compiler.
  • The Snek embedded computing language "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." Snek is compatible with 8-bit AVR microcontrollers such as ATmega 328P-based Arduino, as well as larger microcontrollers that are compatible with MicroPython. Snek is an imperative language that (unlike Python) omits object-oriented programming. Snek supports only one numeric data type, which features 32-bit single precision (resembling JavaScript numbers, though smaller).

Unsupported implementations

Stackless Python is a significant fork of CPython that implements microthreads. This implementation uses the call stack differently, thus allowing massively concurrent programs. PyPy also offers a stackless version.

Just-in-time Python compilers have been developed, but are now unsupported:

  • Google began a project named Unladen Swallow in 2009: this project aimed to speed up the Python interpreter five-fold by using LLVM, and improve multithreading capability for scaling to thousands of cores, while typical implementations are limited by the global interpreter lock.
  • Psyco is a discontinued just-in-time specializing compiler, which integrates with CPython and transforms bytecode to machine code at runtime. The emitted code is specialized for certain data types and is faster than standard Python code. Psyco does not support Python 2.7 or later.
  • PyS60 was a Python 2 interpreter for Series 60 mobile phones, which was released by Nokia in 2005. The interpreter implemented many modules from Python's standard library, as well as additional modules for integration with the Symbian operating system. The Nokia N900 also supports Python through the GTK widget library, allowing programs to be written and run on the target device.

Transpilers to other languages

There are several compilers/transpilers to high-level object languages; the source language is unrestricted Python, a subset of Python, or a language similar to Python:

  • Brython and Transcrypt compile Python to JavaScript.
  • Cython compiles a superset of Python to C. The resulting code can be used with Python via direct C-level API calls into the Python interpreter.
  • PyJL compiles/transpiles a subset of Python to "human-readable, maintainable, and high-performance Julia source code". Despite the developers' performance claims, this is not possible for arbitrary Python code; that is, compiling to a faster language or machine code is known to be impossible in the general case. The semantics of Python might potentially be changed, but in many cases speedup is possible with few or no changes in the Python code. The faster Julia source code can then be used from Python or compiled to machine code.
  • Nuitka compiles Python into C. This compiler works with Python 3.4 to 3.13 (and 2.6 and 2.7) for Python's main supported platforms (and Windows 7 or even Windows XP) and for Android. The compiler developers claim full support for Python 3.10, partial support for Python 3.11 and 3.12, and experimental support for Python 3.13. Nuitka supports macOS including Apple Silicon-based versions. The compiler is free of cost, though it has commercial add-ons (e.g., for hiding source code).
  • Numba is a JIT compiler that is used from Python; the compiler translates a subset of Python and NumPy code into fast machine code. This tool is enabled by adding a decorator to the relevant Python code.
  • Pythran compiles a subset of Python 3 to C++ (C++11).
  • RPython can be compiled to C, and it is used to build the PyPy interpreter for Python.
  • The Python → 11l → C++ transpiler compiles a subset of Python 3 to C++ (C++17).

There are also specialized compilers:

  • MyHDL is a Python-based hardware description language (HDL) that converts MyHDL code to Verilog or VHDL code.

Some older projects existed, as well as compilers not designed for use with Python 3.x and related syntax:

  • Google's Grumpy transpiles Python 2 to Go. The latest release was in 2017.
  • IronPython allows running Python 2.7 programs with the .NET Common Language Runtime. An alpha version (released in 2021), is available for "Python 3.4, although features and behaviors from later versions may be included."
  • Jython compiles Python 2.7 to Java bytecode, allowing the use of Java libraries from a Python program.
  • Pyrex (last released in 2010) and Shed Skin (last released in 2013) compile to C and C++ respectively.

Performance

A performance comparison among various Python implementations, using a non-numerical (combinatorial) workload, was presented at EuroSciPy '13. In addition, Python's performance relative to other programming languages is benchmarked by The Computer Language Benchmarks Game.

There are several approaches to optimizing Python performance, despite the inherent slowness of an interpreted language. These approaches include the following strategies or tools:

  • Just-in-time compilation: Dynamically compiling parts of a Python program during the execution of the program. This technique is used in libraries such as Numba and PyPy.
  • Static compilation: Sometimes, Python code can be compiled into machine code sometime before execution. An example of this approach is Cython, which compiles Python into C.
  • Concurrency and parallelism: Multiple tasks can be run simultaneously. Python contains modules such as multiprocessing to support this form of parallelism. Moreover, this approach helps to overcome limitations of the Global Interpreter Lock (GIL) in CPU tasks.
  • Efficient data structures: Performance can also be improved by using data types such as Set for membership tests, or deque from collections for queue operations.
  • Performance gains can be observed by utilizing libraries such as NumPy. Most high performance Python libraries use C or Fortran under the hood instead of the Python interpreter.

Language Development

Python's development is conducted mostly through the Python Enhancement Proposal (PEP) process; this process is the primary mechanism for proposing major new features, collecting community input on issues, and documenting Python design decisions. Python coding style is covered in PEP 8. Outstanding PEPs are reviewed and commented on by the Python community and the steering council.

Enhancement of the language corresponds with 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 by the foundation. In 2022, all issues and discussions were migrated to GitHub. Development originally took place on a self-hosted source-code repository running Mercurial, until Python moved to GitHub in January 2017.

CPython's public releases have three types, distinguished by which part of the version number is incremented:

  • Backward-incompatible versions, where code is expected to break and must be manually ported. 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 will probably never exist.
  • 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 occur annually. Each major version is supported by bug fixes for several years after its release.
  • Bug fix releases, which introduce no new features, occur approximately every three months; these releases 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.

Many alpha, beta, and release-candidates are also released as previews and for testing before final releases. Although there is a rough schedule for releases, they are often delayed if the code is not ready yet. Python's development team monitors the state of the code by running a large unit test suite during development.

The major academic conference on Python is PyCon. Also, there are special Python mentoring programs, such as PyLadies.

Naming

Python's name is inspired by 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; for example, the metasyntactic variables often used in Python literature are spam and eggs, rather than the traditional foo and bar. Also, the official Python documentation contains various references to Monty Python routines. Python users are sometimes referred to as "Pythonistas".

Languages influenced by Python

  • Cobra has an Acknowledgements document that lists Python first among influencing languages.
  • ECMAScript and JavaScript borrowed iterators and generators from Python.
  • Go is designed for "speed of working in a dynamic language like Python".
  • Julia was designed to be "as usable for general programming as Python".
  • Mojo is almost a superset of Python.
  • GDScript is strongly influenced by Python.
  • Groovy, Boo, CoffeeScript, F#, Nim, Ruby, Swift, and V have been influenced, as well.

Notes

References

Sources

References

  1. "General Python FAQ – Python 3 documentation".
  2. "Python 0.9.1 part 01/21". alt.sources archives.
  3. "Why is Python a dynamic language and also a strongly typed language".
  4. "PEP 483 – The Theory of Type Hints".
  5. "PEP 11 – CPython platform support".
  6. "PEP 738 – Adding Android as a supported platform {{!}} peps.python.org".
  7. "Download Python for Other Platforms".
  8. "test – Regression tests package for Python".
  9. "platform – Access to underlying platform's identifying data".
  10. (30 March 2014). "PEP 0441 – Improving Python ZIP Application Support".
  11. File extension .pyo was removed in Python 3.5. See [https://www.python.org/dev/peps/pep-0488/ PEP 0488] {{Webarchive. link. (1 June 2020)
  12. "Starlark Language".
  13. "Ada 83 Reference Manual (raise statement)".
  14. "itertools – Functions creating iterators for efficient looping".
  15. "re – Regular expression operations".
  16. "CoffeeScript".
  17. Rauschmayer, Axel. (24 February 2013). "Perl and Python influences in JavaScript".
  18. Rauschmayer, Axel. "Chapter 3: The Nature of JavaScript; Influences". O'Reilly.
  19. (February 2012). "Why We Created Julia".
  20. Krill, Paul. (4 May 2023). "Mojo language marries Python and MLIR for AI development".
  21. Lattner, Chris. (3 June 2014). "Chris Lattner's Homepage". Chris Lattner.
  22. "V documentation (Introduction)".
  23. "PEP 484 – Type Hints".
  24. "mypy – Optional Static Typing for Python".
  25. "What's new in Python 3.15".
  26. "Stack Overflow Developer Survey 2022".
  27. "The State of Developer Ecosystem in 2020 Infographic".
  28. "TIOBE Index". TIOBE.
  29. (2017). "Bridging the Cyber-Analysis Gap: The Democratization of Data Science". The Cyber Defense Review.
  30. (2017). "Curriculum for an Introductory Computer Science Course: Identifying Recommendations from Academia and Industry". The Journal of Technology Studies.
  31. "TIOBE Index". TIOBE.
  32. "PEP 8100 – January 2019 Steering Council election". Python Software Foundation.
  33. The Python core team and community. "PEP 13 – Python Language Governance".
  34. (2013). "Python for kids: a playful introduction to programming". No Starch Press.
  35. Peterson, Benjamin. "PEP 373 – Python 2.7 Release Schedule". python.org.
  36. Coghlan, Alyssa. "PEP 466 – Network Security Enhancements for Python 2.7.x".
  37. "Sunsetting Python 2".
  38. Peterson, Benjamin. "PEP 373 – Python 2.7 Release Schedule".
  39. mattip. (25 December 2023). "PyPy v7.3.14 release".
  40. Peterson, Benjamin. (20 April 2020). "Python 2.7.18, the last release of Python 2".
  41. "Status of Python versions".
  42. "Glue it all together with Python".
  43. "Reference counts".
  44. Lutz, Mark. (January 2022). "Python changes 2014+".
  45. (2022-05-03). "Confusion regarding a rule in 'the Zen of Python'".
  46. Ambi, Chetan. (2021-07-04). "The most controversial Python 'walrus operator'".
  47. Grifski, Jeremy. (2020-05-24). "The controversy behind the 'walrus operator' in Python".
  48. (26 June 2013). "[Python-ideas] PEP 315: do-while".
  49. Bader, Dan. "Python string formatting best practices".
  50. "15 ways Python is a powerful force on the web".
  51. "pprint – data pretty printer – {{nobr".
  52. "Code style".
  53. Guttag, John V.. (12 August 2016). "Introduction to Computation and Programming Using Python: With Application to Understanding Data". MIT Press.
  54. "PEP 8 – Style Guide for Python Code".
  55. "8. Errors and Exceptions – Python 3.12.0a0 documentation".
  56. "Highlights: Python 2.5".
  57. "division".
  58. "PEP 0465 – A dedicated infix operator for matrix multiplication".
  59. "Python 3.5.1 Release and Changelog".
  60. "What's New in Python 3.8".
  61. "4. Built-in Types – Python 3.6.3rc1 documentation".
  62. "5.3. Tuples and Sequences – Python 3.7.1rc2 documentation".
  63. "PEP 498 – Literal String Interpolation".
  64. "PEP 484 – Type Hints {{!}} peps.python.org".
  65. "typing — Support for type hints". Python Software Foundation.
  66. "mypy – Optional Static Typing for Python".
  67. "Introduction".
  68. "Built-in Types".
  69. "c – Modulo operation with negative numbers".
  70. "PEP 465 – A dedicated infix operator for matrix multiplication". python.org.
  71. (Oct 29, 2013). "What's New in Python 2.6".
  72. "10 Reasons Python Rocks for Research (And a Few Reasons it Doesn't) – Hoyt Koepke".
  73. Shell, Scott. (17 June 2014). "An introduction to Python for scientific computing".
  74. (2025-03-13). "PyPI".
  75. "Glossary: interactive".
  76. "IDLE — Python editor and shell".
  77. (August 29, 2025). "IPython Documentation".
  78. "Python in Visual Studio Code".
  79. "Project Jupyter".
  80. (Spring 2024). "Enthought Canopy". [[Western Kentucky University]].
  81. "Enthought Canopy".
  82. "PEP 7 – Style Guide for C Code {{!}} peps.python.org".
  83. "4. Building C and C++ Extensions – Python 3.9.2 documentation".
  84. "Changelog – Python 3.9.0 documentation".
  85. "Download Python".
  86. "history [vmspython]".
  87. (2017-10-23). "Proceedings of the 10th ACM SIGPLAN International Conference on Software Language Engineering". Association for Computing Machinery.
  88. "What PyInstaller Does and How It Does It".
  89. Team, The PyPy. (2019-12-28). "Download and Install".
  90. "Codon: Differences with Python".
  91. Lawson, Loraine. (2023-03-14). "MIT-Created Compiler Speeds up Python Code".
  92. "Python-for-EV3".
  93. Yegulalp, Serdar. (29 October 2020). "Pyston returns from the dead to speed Python".
  94. "cinder: Instagram's performance-oriented fork of CPython.".
  95. Aroca, Rafael. (2021-08-07). "Snek Lang: feels like Python on Arduinos".
  96. Aufranc (CNXSoft), Jean-Luc. (2020-01-16). "Snekboard Controls LEGO Power Functions with CircuitPython or Snek Programming Languages (Crowdfunding) – CNX Software".
  97. Kennedy (@mkennedy), Michael. "Ready to find out if you're git famous?".
  98. Packard, Keith. (2022-12-20). "The Snek Programming Language: A Python-inspired Embedded Computing Language".
  99. (29 April 2010). "Python on the Nokia N900".
  100. "Brython".
  101. "Transcrypt – Python in the browser".
  102. "Transcrypt: Anatomy of a Python to JavaScript Compiler".
  103. "Transpiling Python to Julia using PyJL".
  104. "Nuitka Home {{!}} Nuitka Home".
  105. (16 March 2015). "Pythran: enabling static optimization of scientific Python programs". IOP Publishing.
  106. "The Python → 11l → C++ transpiler".
  107. (10 April 2020). "google/grumpy".
  108. "Projects".
  109. Francisco, Thomas Claburn in San. "Google's Grumpy code makes Python Go".
  110. "IronPython.net /".
  111. "GitHub – IronLanguages/ironpython3: Implementation of Python 3.x for .NET Framework that is built on top of the Dynamic Language Runtime".
  112. "Jython FAQ".
  113. Murri, Riccardo. (2013). "Performance of Python runtimes on a non-numeric scientific code".
  114. "The Computer Language Benchmarks Game".
  115. Python, Real. "Look Ma, No for Loops: Array Programming With NumPy – Real Python".
  116. (23 February 2022). "Moving Python's bugs to GitHub [LWN.net]".
  117. "Python Developer's Guide – Python Developer's Guide".
  118. Hughes, Owen. (2021-05-24). "Programming languages: Why Python 4.0 might never arrive, according to its creator".
  119. "PEP 602 – Annual Release Cycle for Python".
  120. (23 October 2019). "Changing the Python release cadence [LWN.net]".
  121. (2002). "Python". Peachpit Press.
  122. Lubanovic, Bill. (2014). "Introducing Python". Sebastopol, CA : O'Reilly Media.
  123. Esterbrook, Charles. "Acknowledgements". Cobra Language.
  124. ["Proposals: iterators and generators ES4 Wiki]". wiki.ecmascript.org.
  125. Kincaid, Jason. (10 November 2009). "Google's Go: A New Programming Language That's Python Meets C++". TechCrunch.
  126. (February 2012). "Why We Created Julia".
  127. "Modular Docs – Why Mojo".
  128. Spencer, Michael. (4 May 2023). "What is Mojo Programming Language?".
  129. "GDScript".
  130. "uv".
  131. "Why was Python created in the first place?". Python Software Foundation.
  132. Kuchling, Andrew M.. (22 December 2006). "Interview with Guido van Rossum (July 1998)". amk.ca.
  133. van Rossum, Guido. (1993). "An Introduction to Python for UNIX/C Programmers". Proceedings of the NLUUG Najaarsconferentie (Dutch UNIX Users Group).
  134. "Classes". Python Software Foundation.
  135. Lundh, Fredrik. "Call By Object". effbot.org.
  136. Simionato, Michele. "The Python 2.3 Method Resolution Order". Python Software Foundation.
  137. Kuchling, A. M.. "Functional Programming HOWTO". Python Software Foundation.
  138. (11 March 2001). "PEP 238 – Changing the Division Operator". Python Software Foundation.
  139. (18 May 2001). "PEP 255 – Simple Generators". Python Software Foundation.
  140. "More Control Flow Tools". Python Software Foundation.
  141. Kuhlman, Dave. "A Python Book: Beginning Python, Advanced Python, and Python Exercises".
  142. Venners, Bill. (13 January 2003). "The Making of Python". Artima.
  143. van Rossum, Guido. (20 January 2009). "A Brief Timeline of Python". The History of Python.
  144. van Rossum, Guido. (29 August 2000). "SETL (was: Lukewarm about range literals)".
  145. (16 October 2000). "What's New in Python 2.0". Python Software Foundation.
  146. The Cain Gang Ltd.. "Python Metaclasses: Who? Why? When?".
  147. "3.3. Special method names". Python Software Foundation.
  148. "PyDBC: method preconditions, method postconditions and class invariants for Python".
  149. "Contracts for Python".
  150. "PyDatalog".
  151. "6.5 itertools – Functions creating iterators for efficient looping". Docs.python.org.
  152. Peters, Tim. (19 August 2004). "PEP 20 – The Zen of Python". Python Software Foundation.
  153. (2005). "Python Cookbook, 2nd Edition". [[O'Reilly Media]].
  154. (January 21, 2014). "Python Culture".
  155. (13 June 2000). "PEP 1 – PEP Purpose and Guidelines". Python Software Foundation.
  156. Cannon, Brett. "Guido, Some Guys, and a Mailing List: How Python is Developed". Python Software Foundation.
  157. Norwitz, Neal. (8 April 2002). "[Python-Dev] Release Schedules (was Stability & change)".
  158. (15 March 2001). "PEP 6 – Bug Fix Releases". Python Software Foundation.
  159. "Python Buildbot". Python Software Foundation.
  160. "Why is it called Python?". Docs.python.org.
  161. "Whetting Your Appetite". Python Software Foundation.
  162. (17 February 2011). "In Python, should I use else after a return in an if block?". Stack Exchange.
  163. "Is Python a good language for beginning programmers?". Python Software Foundation.
  164. "Myths about indentation in Python". Secnetix.de.
  165. van Rossum, Guido. (22 April 2009). "Tail Recursion Elimination". Neopythonic.blogspot.be.
  166. van Rossum, Guido. (9 February 2006). "Language Design Is Not Just Solving Puzzles". Artima.
  167. (10 May 2005). "PEP 342 – Coroutines via Enhanced Generators". Python Software Foundation.
  168. "PEP 380". Python.org.
  169. Hettinger, Raymond. (30 January 2002). "PEP 289 – Generator Expressions". Python Software Foundation.
  170. (7 February 2003). "PEP 308 – Conditional Expressions". Python Software Foundation.
  171. "The Python Language Reference, section 3.3. New-style and classic classes, for release 2.7.1".
  172. (11 March 2001). "PEP 237 – Unifying Long Integers and Integers". Python Software Foundation.
  173. (24 August 2010). "Why Python's Integer Division Floors".
  174. "round". The Python standard library, release 2.7, §2: Built-in functions.
  175. "round". The Python standard library, release 3.2, §2: Built-in functions.
  176. (2009). "Python Essential Reference". Addison-Wesley Professional.
  177. (1988). "The C Programming Language".
  178. van Rossum, Guido. (5 June 2001). "PEP 7 – Style Guide for C Code". Python Software Foundation.
  179. "CPython byte code". Docs.python.org.
  180. "Python 2.5 internals".
  181. "An Interview with Guido van Rossum". Oreilly.com.
  182. "PyPy compatibility". Pypy.org.
  183. "speed comparison between CPython and Pypy". Speed.pypy.org.
  184. "Application-level Stackless features – PyPy 2.0.2 documentation". Doc.pypy.org.
  185. (15 December 2009). "Plans for optimizing Python". Google Project Hosting.
  186. Piotrowski, Przemyslaw. (July 2006). "Build a Rapid Web Development Environment for Python Server Pages and Oracle". Oracle.
  187. Batista, Facundo. (17 October 2003). "PEP 327 – Decimal Data Type". Python Software Foundation.
  188. Eby, Phillip J.. (7 December 2003). "PEP 333 – Python Web Server Gateway Interface v1.0". Python Software Foundation.
  189. Fairchild, Carlie. (12 July 2018). "Guido van Rossum Stepping Down from Role as Python's Benevolent Dictator For Life".
Info: Wikipedia Source

This article was imported from Wikipedia and is available under the Creative Commons Attribution-ShareAlike 4.0 License. Content has been adapted to SurfDoc format. Original contributors can be found on the article history page.

Want to explore this topic further?

Ask Mako anything about Python (programming language) — get instant answers, deeper analysis, and related topics.

Research with Mako

Free with your Surf account

Content sourced from Wikipedia, available under CC BY-SA 4.0.

This content may have been generated or modified by AI. CloudSurf Software LLC is not responsible for the accuracy, completeness, or reliability of AI-generated content. Always verify important information from primary sources.

Report