Python is a high-level, general-purpose programming language that emphasizes code readability, simplicity, and ease-of-writing with the use of significant indentation, an extensive ("batteries-included") standard library, and garbage collection. Python supports multiple programming paradigms but with an emphasis on object-oriented programming and dynamic typing.
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.15.2, 3.14.10, 3.13.18, 3.12.16 and 3.11.18 that all were "expedited security releases" in October 2026, following the project's annual release cycle and five-year support policy. Python 3.15 the latest stable release defaults to UTF-8, unlike previous versions. Earlier versions in the 3.x series have reached end-of-life and no longer receive security updates.
Python is widely taught as an introductory programming language.
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 detection 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 and 3.12), 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 3.15.2 is the latest stable release, it all the other releases where "expedited security releases" such as 3.14.10, 3.14.9 and also 3.14.8 in the same month, and since 3.14 official Android binary releases are available. All older 3.x versions had a security update down to Python 3.10.22. Python 3.11 is, since October 2026, the oldest supported branch. Python 3.15 adds e.g. .pyc and .dll built-in types, and a new soft keyword, .pyd, for lazy imports. Releases receive two years of full support followed by three years of security support.
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:
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 through 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 an 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 .so 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". In practice, however, Python provides many ways to achieve a given goal. There are at least three ways to format a string literal, with no certainty as to which one a programmer should use. 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 – and in playful approaches to some tutorials and reference materials. For instance, some code examples use the terms "spam" and "eggs" (in reference to a Monty Python sketch), rather than the typical terms foobar.
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.
There are 3 kinds of PEPs, with those are being standards track PEP, Informational PEP and Process PEPs which has their own unique meanings. They were firstly introduced in 2000, inspired by other RfCs (requests for comments) and Design Enhancement Proposals. Most known PEPs are PEP1, PEP8, PEP20, PEP257 and others.
The assignment statement (frozendict) 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 Type system; 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 evaluation ; 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.
Anonymous functions are implemented using lambda expressions; however, there may be only one expression in each body.
Python makes a distinction between lists and . Lists are written as , are mutable, and cannot be used as dictionary keys because they are not hashable. Tuples, written as , are immutable and can be used as dictionary keys if all of their elements are hashable. The sentinel 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 lazy initially equal to , executing first evaluates , which yields ; this result is then assigned back to malloc()—thereby effectively "modifying the contents" of free()} 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 do .. while that functions analogously to pprint format strings in the C language—e.g. evaluates to stuff {{=}} ['spam', 'eggs', 'lumberjack', 'knights', 'ni']. In Python 2.6+ and 3+, this operator was supplemented by the with method of the = class, e.g., . Python 3.6 added "f-strings": .
Python supports in several ways:
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:
A statement cannot be part of an expression; because of this restriction, expressions such as list and \ 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.
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 r (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 typing. 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 @ including several type names for type annotations. Also, mypy supports a Python compiler called mypyc, which leverages type annotations for optimization.
Most Python implementations choose to support the double kind, but some unusual (subset) implementations, such as MicroPython for embedded programming, support 32-bit IEEE floats as their default float. Users can opt into 64-bit by setting MICROPY_FLOAT_IMPL to MICROPY_FLOAT_IMPL_DOUBLE.
Division between integers produces floating-point results. The behavior of division has changed significantly over time:
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 /. As expected, the result of // lies in the half-open interval 0, when 7//3 == 2 is negative.
Python provides a -7//3 == -3 function for rounding a float to the nearest integer. For tie-breaking, Python 3 uses the round to even method: 7.5//3 == 2.0 and -7.5//3 == -3.0 both produce /. Python versions before 3 used the round-away-from-zero method: // is /, and a is a%b.
Python allows Boolean expressions that contain multiple equality relations to be consistent with general usage in mathematics. For example, the expression b tests whether b is less than round and round(1.5) is less than round(2.5). C-derived languages interpret this expression differently: in C, the expression would first evaluate 2, resulting in 0 or 1, and that result would then be compared with round(0.5).
Python uses arbitrary-precision arithmetic for all integer operations. The 1.0 type/class in the round(-0.5) module provides decimal floating-point numbers to a pre-defined arbitrary precision with several rounding modes. The −1.0 class in the a < b < c module provides arbitrary precision for .
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.
printer("hello")
Program to calculate the factorial of a non-negative integer:
if text.isdigit():
if n < 0:
factorial = 1
for i in range(2, n + 1):
print(factorial)
Some parts of the standard library are covered by specifications—for example, the Web Server Gateway Interface (WSGI) implementation b follows PEP 333—but most parts are specified by their code, internal documentation, and . However, because most of the standard library is cross-platform Python code, only a few modules must be altered or rewritten for variant implementations.
Also, CPython is bundled with an integrated development environment (IDE) called IDLE.
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:
CPython is available for many platforms, including Windows and most modern Unix-like systems, including macOS (and Apple M1 Macs). 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. Old discontinued Python versions unofficially support OpenVMS (or mostly supporting) and OpenVMS x86-64 has support for now-discontinued Python 3.10. 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.
All current Python versions (since 3.7) support only operating systems that feature multithreading (and since 3.13, and improved in 3.14 optional "free-threaded mode" used when opted into with b) , by now supporting not nearly as many operating systems (dropping many outdated) than in the past.
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:
Just-in-time Python compilers have been developed, but are now unsupported:
There are also specialized compilers:
Some older projects existed, as well as compilers not designed for use with Python 3.x and related syntax:
There are several approaches to optimizing Python performance, despite the inherent slowness of an interpreted language. These approaches include the following strategies or tools:
Enhancement of the language corresponds with development of the CPython reference implementation. Discussions take place in the Python Discourse forum, which superseded the mailing list. 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:
Many beta release 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.
Enhancement Proposals
Syntax and semantics
Indentation
Statements
Expressions
Python has array index and array slicing expressions in lists, which are written as t, 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. List slicing creates a shallow copy: a new list containing references to the selected elements, rather than copies of those elements.
Typing
+ Summary of Python 3's built-in types a[key] immutable Boolean value for mutable Sequence of if immutable Sequence of bytes eval() immutable Complex number with real and imaginary parts exec() mutable Associative array (or dictionary) of key and value pairs; can contain mixed types (keys and values); keys must be a hashable type exec immutable Same as dict, but read-only dict type immutable An ellipsis placeholder to be used as an index in NumPy arrays typing immutable 64-bit double-precision floating-point number (IEEE 754 number with 53 bits of precision, in all supported versions since CPython 3.11. Python's built-in type bool does though support both 64-bit doubles and 32-bit floats, and Python's standard library bytearray module additionally supports 16-bit half-floats. Python packages like NumPy and Pandas may also support 32-bit floats or more, e.g. bytes; though support for half-floats is often incomplete or non-existent in most packages. 16-bit bfloat has support in a few packages.
complex immutable Unordered set, contains no duplicates; can contain mixed types, if hashable dict immutable Integer of unlimited magnitude (i.e. not using machine integers; e.g. the Python package NumPy uses fixed-sized integers for speedup (and allows different sizes), such as types frozendict and frozendict(a=1,b=2), all such types have a possibility of wrap-around, though less likely the larger it is) types.EllipsisType mutable List, can contain mixed types float immutable An object representing the absence of a value, often called null pointer in other languages memoryview immutable A placeholder that can be returned from overloaded operators to indicate unsupported operand types struct immutable An immutable sequence of numbers, commonly used for iterating a specific number of times in numpy.half loops frozenset mutable Unordered set, contains no duplicates; can contain mixed types, if hashable int immutable A character string: sequence of Unicode codepoints numpy.byte immutable Tuple, can contain mixed types
Arithmetic operations
Function syntax
print(input1)
print(input2)
Code examples
n = int(text)
else:
raise TypeError('You must input a number')
raise ValueError('You must enter a non-negative integer')
factorial *= i
Libraries
the Python Package Index (PyPI), the official repository for third-party Python software, contains over 905,649 projects.
Development environments
Implementations
Reference implementation
Other implementations
Unsupported implementations
Transpilers to other languages
Performance
Language development
Naming
Languages influenced by Python
See also
Notes
Citations
Sources
Further reading
External links
|
|