Python (programming language)#Naming
{{Short description|General-purpose programming language}}
{{Use dmy dates|date=November 2021}}
{{Use American English|date=December 2024}}
{{Infobox programming language
| logo = Python-logo-notext.svg
| logo size = 150px
| paradigm = Multi-paradigm: object-oriented,{{Cite web|title=General Python FAQ – Python 3 documentation|url=https://docs.python.org/3/faq/general.html#what-is-python|access-date=2024-07-07|website=docs.python.org}} procedural (imperative), functional, structured, reflective
| released = {{start date and age|1991|02|20|df=y}}{{cite web |url=https://www.tuhs.org/Usenet/alt.sources/1991-February/001749.html |title=Python 0.9.1 part 01/21 |publisher=alt.sources archives |access-date=2021-08-11 |archive-date=11 August 2021 |archive-url=https://web.archive.org/web/20210811171015/https://www.tuhs.org/Usenet/alt.sources/1991-February/001749.html |url-status=live}}
| designer = Guido van Rossum
| developer = Python Software Foundation
| latest release version = {{wikidata|property|P548=Q2804309|P348}}
| latest release date = {{start date and age|{{wikidata|qualifier|single|P548=Q2804309|P348|P577}}}}
| latest preview version = {{wikidata|property|edit|reference|P548=Q51930650|P348}}
| latest preview date = {{start date and age|{{wikidata|qualifier|single|P548=Q51930650|P348|P577}}}}
| typing = duck, dynamic, strong;{{Cite web|title=Why is Python a dynamic language and also a strongly typed language |url=https://wiki.python.org/moin/Why%20is%20Python%20a%20dynamic%20language%20and%20also%20a%20strongly%20typed%20language|access-date=2021-01-27|website=Python Wiki |archive-date=14 March 2021|archive-url=https://web.archive.org/web/20210314173706/https://wiki.python.org/moin/Why%20is%20Python%20a%20dynamic%20language%20and%20also%20a%20strongly%20typed%20language|url-status=live}} optional type annotations (since 3.5, but those hints are ignored, except with unofficial tools){{cite web|url=https://www.python.org/dev/peps/pep-0483/|title=PEP 483 – The Theory of Type Hints|website=Python.org|access-date=14 June 2018|archive-date=14 June 2020|archive-url=https://web.archive.org/web/20200614153558/https://www.python.org/dev/peps/pep-0483/|url-status=live}}
| implementations = CPython, PyPy, Stackless Python, MicroPython, CircuitPython, IronPython, Jython
| operating system = {{plainlist|
- Tier 1: 64-bit Linux, macOS; 64- and 32-bit Windows 10+{{Cite web |title=PEP 11 – CPython platform support {{!}} peps.python.org |url=https://peps.python.org/pep-0011/ |access-date=2024-04-22 |website=Python Enhancement Proposals (PEPs) |language=en}}
- Tier 2: E.g. 32-bit WebAssembly (WASI)
- Tier 3: 64-bit Android,{{Cite web |title=PEP 738 – Adding Android as a supported platform {{!}} peps.python.org |url=https://peps.python.org/pep-0738/ |access-date=2024-05-19 |website=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{{Cite web |title=Download Python for Other Platforms |url=https://www.python.org/download/other/ |access-date=2023-08-18 |website=Python.org |language=en |archive-date=27 November 2020 |archive-url=https://web.archive.org/web/20201127015815/https://www.python.org/download/other/ |url-status=live}}{{Cite web |title=test – Regression tests package for Python – Python 3.7.13 documentation |url=https://docs.python.org/3.7/library/test.html?highlight=android#test.support.is_android |access-date=2022-05-17 |website=docs.python.org |archive-date=17 May 2022 |archive-url=https://web.archive.org/web/20220517151240/https://docs.python.org/3.7/library/test.html?highlight=android#test.support.is_android |url-status=live}}{{Cite web |title=platform – Access to underlying platform's identifying data – Python 3.10.4 documentation |url=https://docs.python.org/3/library/platform.html?highlight=android |access-date=2022-05-17 |website=docs.python.org |archive-date=17 May 2022 |archive-url=https://web.archive.org/web/20220517150826/https://docs.python.org/3/library/platform.html?highlight=android |url-status=live}}}}
| license = Python Software Foundation License
.pyi, .pyc, .pyd
| website = {{URL|https://www.python.org/|python.org}}
| dialects = Cython, RPython, Starlark{{cite web|title=Starlark Language|url=https://docs.bazel.build/versions/master/skylark/language.html|access-date=25 May 2019|archive-date=15 June 2020|archive-url=https://web.archive.org/web/20200615140534/https://docs.bazel.build/versions/master/skylark/language.html|url-status=live}}
| influenced by = ABC, Ada,{{cite web |url=https://archive.adaic.com/standards/83lrm/html/lrm-11-03.html#11.3 |title=Ada 83 Reference Manual (raise statement) |access-date=7 January 2020 |archive-date=22 October 2019 |archive-url=https://web.archive.org/web/20191022155758/http://archive.adaic.com/standards/83lrm/html/lrm-11-03.html#11.3 |url-status=live}} ALGOL 68,
APL,{{cite web|url=https://docs.python.org/3/library/itertools.html|title=itertools – Functions creating iterators for efficient looping – Python 3.7.1 documentation|website=docs.python.org|access-date=22 November 2016|archive-date=14 June 2020|archive-url=https://web.archive.org/web/20200614153629/https://docs.python.org/3/library/itertools.html |quote=This module implements a number of iterator building blocks inspired by constructs from APL, Haskell, and SML. |url-status=live}} C, C++, CLU, Dylan,
Haskell, Icon, Lisp, {{nowrap|
Modula-3}},{{r|98-interview}} Perl,{{cite web |title=re – Regular expression operations – Python 3.10.6 documentation |url=https://docs.python.org/3/library/re.html |website=docs.python.org |access-date=2022-09-06 |quote=This module provides regular expression matching operations similar to those found in Perl. |archive-date=18 July 2018 |archive-url=https://web.archive.org/web/20180718132241/https://docs.python.org/3/library/re.html |url-status=live}} Standard ML| influenced = Apache Groovy, Boo, Cobra, CoffeeScript,{{Cite web|url=https://coffeescript.org/|title=CoffeeScript|website=coffeescript.org|access-date=3 July 2018|archive-date=12 June 2020|archive-url=https://web.archive.org/web/20200612100004/http://coffeescript.org/|url-status=live}} D, F#, GDScript, Go, JavaScript,{{cite web
|title=Perl and Python influences in JavaScript
|date=24 February 2013
|website=www.2ality.com
|url=https://www.2ality.com/2013/02/javascript-influences.html
|access-date=15 May 2015
|archive-date=26 December 2018
|archive-url=https://web.archive.org/web/20181226141121/http://2ality.com/2013/02/javascript-influences.html%0A
|url-status=live
|title=Chapter 3: The Nature of JavaScript; Influences
|last=Rauschmayer
|first=Axel
|website=O'Reilly, Speaking JavaScript
|url=http://speakingjs.com/es5/ch03.html
|access-date=15 May 2015
|archive-date=26 December 2018
|archive-url=https://web.archive.org/web/20181226141123/http://speakingjs.com/es5/ch03.html%0A
|url-status=live
}} Julia, Mojo,{{Cite web |last=Krill |first=Paul |date=2023-05-04 |title=Mojo language marries Python and MLIR for AI development |url=https://www.infoworld.com/article/3695588/mojo-language-marries-python-and-mlir-for-ai-development.html |access-date=2023-05-05 |website=InfoWorld |language=en |archive-date=5 May 2023 |archive-url=https://web.archive.org/web/20230505064554/https://www.infoworld.com/article/3695588/mojo-language-marries-python-and-mlir-for-ai-development.html |url-status=live}} Nim, Ring,{{cite web |url=https://ring-lang.sourceforge.net/doc1.6/introduction.html#ring-and-other-languages |title=Ring and other languages |author=Ring Team |date=4 December 2017 |work=ring-lang.net |publisher=ring-lang |access-date=4 December 2017 |archive-date=25 December 2018 |archive-url=https://web.archive.org/web/20181225175312/http://ring-lang.sourceforge.net/doc1.6/introduction.html#ring-and-other-languages |url-status=live}} Ruby, Swift,{{Cite web |url=http://nondot.org/sabre/ |title=Chris Lattner's Homepage |last=Lattner |first=Chris |date=3 June 2014 |access-date=3 June 2014 |publisher=Chris Lattner |quote=The Swift language is the product of tireless effort from a team of language experts, documentation gurus, compiler optimization ninjas, and an incredibly important internal dogfooding group who provided feedback to help refine and battle-test ideas. Of course, it also greatly benefited from the experiences hard-won by many other languages in the field, drawing ideas from Objective-C, Rust, Haskell, Ruby, Python, C#, CLU, and far too many others to list. |archive-date=25 December 2018 |archive-url=https://web.archive.org/web/20181225175312/http://nondot.org/sabre/ |url-status=live}} V{{Cite web |title=V documentation (Introduction) |url=https://github.com/vlang/v/blob/master/doc/docs.md#introduction |access-date=2024-12-24|website=GitHub |language=en}}
| wikibooks = Python Programming
}}
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. It is often described as a "batteries included" language due to its comprehensive standard library.{{Cite web|title=PEP 206 – Python Advanced Library|url=https://www.python.org/dev/peps/pep-0206/|url-status=live|archive-url=https://web.archive.org/web/20210505003659/https://www.python.org/dev/peps/pep-0206/|archive-date=5 May 2021|access-date=11 October 2021|website=Python.org}}
Guido van Rossum began working on Python in the late 1980s as a successor to the ABC programming language, and he first released it in 1991 as Python 0.9.0.{{Cite web|last=Rossum|first=Guido Van|date=2009-01-20|title=The History of Python: A Brief Timeline of Python|url=https://python-history.blogspot.com/2009/01/brief-timeline-of-python.html|access-date=2021-03-05|website=The History of Python|archive-date=5 June 2020|archive-url=https://web.archive.org/web/20200605032200/https://python-history.blogspot.com/2009/01/brief-timeline-of-python.html|url-status=live}} 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.{{Cite web|url=https://pythoninsider.blogspot.com/2020/04/python-2718-last-release-of-python-2.html|title= Python 2.7.18, the last release of Python 2|last=Peterson|first=Benjamin|date=20 April 2020|website=Python Insider|access-date=27 April 2020|archive-date=26 April 2020|archive-url=https://web.archive.org/web/20200426204118/https://pythoninsider.blogspot.com/2020/04/python-2718-last-release-of-python-2.html|url-status=live}}
Python consistently ranks as one of the most popular programming languages, and it has gained widespread use in the machine learning community.{{Cite web |title=Stack Overflow Developer Survey 2022 |url=https://survey.stackoverflow.co/2022/ |access-date=2022-08-12 |website=Stack Overflow |language=en |archive-date=27 June 2022 |archive-url=https://web.archive.org/web/20220627175307/https://survey.stackoverflow.co/2022/ |url-status=live}}{{Cite web|title=The State of Developer Ecosystem in 2020 Infographic|url=https://www.jetbrains.com/lp/devecosystem-2020/|access-date=2021-03-05|website=JetBrains: Developer Tools for Professionals and Teams|language=en|archive-date=1 March 2021|archive-url=https://web.archive.org/web/20210301062411/https://www.jetbrains.com/lp/devecosystem-2020/|url-status=live}}{{cite web |title=TIOBE Index |publisher=TIOBE |url=https://www.tiobe.com/tiobe-index/ |access-date=3 January 2023 |quote=The TIOBE Programming Community index is an indicator of the popularity of programming languages |archive-date=25 February 2018 |archive-url=https://web.archive.org/web/20180225101948/https://www.tiobe.com/tiobe-index/ |url-status=live}} Updated as required.{{Cite web|title=PYPL PopularitY of Programming Language index|url=https://pypl.github.io/PYPL.html|access-date=2021-03-26|website=pypl.github.io|language=en|archive-date=14 March 2017|archive-url=https://web.archive.org/web/20170314232030/https://pypl.github.io/PYPL.html|url-status=live}}
History
{{Main|History of Python}}
File:Guido van Rossum in PyConUS24.jpg, at PyCon US 2024]]
Python was conceived in the late 1980s by Guido van Rossum at Centrum Wiskunde & Informatica (CWI) in the Netherlands; it was conceived 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 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.{{cite web |title=PEP 8100 |url=https://www.python.org/dev/peps/pep-8100/ |publisher=Python Software Foundation |access-date=4 May 2019 |archive-date=4 June 2020 |archive-url=https://web.archive.org/web/20200604235027/https://www.python.org/dev/peps/pep-8100/ |url-status=live}}{{Cite web|title=PEP 13 – Python Language Governance|url=https://www.python.org/dev/peps/pep-0013/|access-date=2021-08-25|website=Python.org|language=en|archive-date=27 May 2021|archive-url=https://web.archive.org/web/20210527000035/https://www.python.org/dev/peps/pep-0013/|url-status=live}}
The name Python is said to derive from the British comedy series Monty Python's Flying Circus.{{Cite book |last1=Briggs |first1=Jason R. |title=Python for kids: a playful introduction to programming |last2=Lipovača |first2=Miran |date=2013 |publisher=No Starch Press |isbn=978-1-59327-407-8 |location=San Francisco, Calif}}
Python 2.0 was released on 16 October 2000, with many major 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.{{cite web |url=https://legacy.python.org/dev/peps/pep-0373/ |title=PEP 373 – Python 2.7 Release Schedule |work=python.org |access-date=9 January 2017 |archive-date=19 May 2020 |archive-url=https://web.archive.org/web/20200519075520/https://legacy.python.org/dev/peps/pep-0373/ |url-status=live}}{{cite web |url=https://www.python.org/dev/peps/pep-0466/ |title=PEP 466 – Network Security Enhancements for Python 2.7.x |work=python.org |access-date=9 January 2017 |archive-date=4 June 2020 |archive-url=https://web.archive.org/web/20200604232833/https://www.python.org/dev/peps/pep-0466/ |url-status=live}} It no longer receives security patches or updates.{{Cite web|url=https://www.python.org/doc/sunset-python-2/|title=Sunsetting Python 2|website=Python.org|language=en|access-date=22 September 2019|archive-date=12 January 2020|archive-url=https://web.archive.org/web/20200112080903/https://www.python.org/doc/sunset-python-2/|url-status=live}}{{Cite web|url=https://www.python.org/dev/peps/pep-0373/|title=PEP 373 – Python 2.7 Release Schedule|website=Python.org|language=en|access-date=22 September 2019|archive-date=13 January 2020|archive-url=https://web.archive.org/web/20200113033257/https://www.python.org/dev/peps/pep-0373/|url-status=live}} 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.10), with the plus signifying (at least some) "backported security updates".{{Cite web |last=mattip |date=2023-12-25 |title=PyPy v7.3.14 release |url=https://www.pypy.org/posts/2023/12/pypy-v7314-release.html |access-date=2024-01-05 |website=PyPy |language=en |archive-date=5 January 2024 |archive-url=https://web.archive.org/web/20240105132820/https://www.pypy.org/posts/2023/12/pypy-v7314-release.html |url-status=live}}
Python 3.0 was released on 3 December 2008, with some new semantics and changed syntax. At least every Python release since (the now unsupported) 3.5 has added some syntax to the language; a few later releases have removed outdated modules and have changed semantics, at least in a minor way.
{{As of|2025|04|08|since=n}}, Python 3.13.3 is the latest stable release (it's highly recommended to upgrade to it, or upgrade any other older 3.x release). This version currently receives full bug-fix and security updates, while Python 3.12—released in October 2023—had active bug-fix support only until April 2025, and since then only security fixes. Python 3.9{{Cite web |last=Langa |first=Łukasz |date=2022-05-17 |title=Python 3.9.13 is now available |url=https://pythoninsider.blogspot.com/2022/05/python-3913-is-now-available.html |access-date=2022-05-21 |website=Python Insider |archive-date=17 May 2022 |archive-url=https://web.archive.org/web/20220517173546/https://pythoninsider.blogspot.com/2022/05/python-3913-is-now-available.html |url-status=live}} is the oldest supported version of Python (albeit in the 'security support' phase), because Python 3.8 has become an end-of-life product.{{Cite web |title=Status of Python versions |url=https://devguide.python.org/versions/ |access-date=2024-10-07 |website=Python Developer's Guide |language=en}}{{Cite web |date=8 October 2024 |title=Python |url=https://endoflife.date/python |access-date=2024-11-20 |website=endoflife.date |language=en-US }} Starting with Python 3.13, it and later versions receive two years of full support (which has increased from one and a half years), followed by three years of security support; this is the same total duration of support as previously.
Security updates were expedited in 2021 and again twice in 2022. More issues were fixed in 2023 and in September 2024 (for Python versions 3.8.20 through 3.12.6)—all versions (including 2.7){{Cite web|title=CVE-2021-3177 |url=https://access.redhat.com/security/cve/cve-2021-3177|access-date=2021-02-26|website=Red Hat Customer Portal |archive-date=6 March 2021|archive-url=https://web.archive.org/web/20210306183700/https://access.redhat.com/security/cve/cve-2021-3177|url-status=live}} had been insecure because of issues leading to possible remote code execution{{Cite web|title=CVE-2021-3177|url=https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2021-3177|access-date=2021-02-26|website=CVE|archive-date=27 February 2021|archive-url=https://web.archive.org/web/20210227192918/https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2021-3177|url-status=live}} and web-cache poisoning.{{Cite web|title=CVE-2021-23336|url=https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2021-23336|access-date=2021-02-26|website=CVE|archive-date=24 February 2021|archive-url=https://web.archive.org/web/20210224160700/https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2021-23336|url-status=live}}
Python 3.10 added the |
union type operator{{cite web | url=https://docs.python.org/3/library/stdtypes.html#types-union | title=Built-in Types }} and added structural pattern matching capability to the language, with the new match
and case
keywords.{{Cite web |title=PEP 634 – Structural Pattern Matching: Specification |url=https://www.python.org/dev/peps/pep-0634/ |url-status=live |archive-url=https://web.archive.org/web/20210506005315/https://www.python.org/dev/peps/pep-0634/ |archive-date=6 May 2021 |access-date=2021-02-14 |website=Python.org |language=en}} Python 3.11 expanded exception handling functionality. Python 3.12 added the new keyword type
. Notable changes from version 3.10 to 3.11 include increased program execution speed and improved error reporting.{{Cite web |title=Python 3.11 released [LWN.net] |author=corbet |work=lwn.net |date=24 October 2022 |access-date=15 November 2022 |url=https://lwn.net/Articles/912216/}} Python 3.11 is claimed to be 10–60% faster than Python 3.10, and Python 3.12 increases by an additional 5%. Python 3.12 also includes improved error messages (again improved in 3.14) and many other changes.
Python 3.13 introduced more syntax for types; a new and improved interactive interpreter (REPL), featuring multi-line editing and color support; an incremental garbage collector, which results in shorter pauses for collection in programs that have many objects, as well as increasing the improved speed in 3.11 and 3.12); an experimental just-in-time (JIT) compiler (such features need to be enabled specifically for the increase in speed);{{Cite web |title=What's New In Python 3.13 |url=https://docs.python.org/3.13/whatsnew/3.13.html#experimental-jit-compiler |access-date=2024-04-30 |website=Python documentation |language=en}} and an experimental free-threaded build mode, which disables the global interpreter lock (GIL), allowing threads to run more concurrently, as enabled inpython3.13t
or python3.13t.exe
.
Python Enhancement Proposal (PEP) 711 proposes PyBI—a standard format for distributing Python binaries.{{Cite web |date=2023-04-07 |title=PEP 711: PyBI: a standard format for distributing Python Binaries |url=https://discuss.python.org/t/pep-711-pybi-a-standard-format-for-distributing-python-binaries/25547 |access-date=2024-11-20 |website=Discussions on Python.org |language=en}}
Python 3.14.0 is now in the beta 1 phase (introduces e.g. a new opt-in interpreter, up to 30% faster).
Python 3.15 will "Make UTF-8 mode default";{{Cite web |title=PEP 686 – Make UTF-8 mode default {{!}} peps.python.org |url=https://peps.python.org/pep-0686/ |access-date=2024-11-20 |website=Python Enhancement Proposals (PEPs) |language=en}} This mode is supported in all current Python versions, but it currently must be opted into. UTF-8 is already used by default on Windows (and other operating systems) for most purposes; an exception is opening files. Enabling UTF-8 also makes code fully cross-platform.
;Potentially breaking changes
Python 3.0 introduced very breaking changes, but all breaking changes in 3.x discussed below, are designed to affect few users.
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. Python 3.12 removed wstr
meaning Python extensions{{Cite web |title=1. Extending Python with C or C++ – Python 3.9.1 documentation |url=https://docs.python.org/3/extending/extending.html |url-status=live |archive-url=https://web.archive.org/web/20200623232830/https://docs.python.org/3/extending/extending.html |archive-date=23 June 2020 |access-date=2021-02-14 |website=docs.python.org}} need to be modified.{{Cite web |title=PEP 623 – Remove wstr from Unicode |url=https://www.python.org/dev/peps/pep-0623/ |url-status=live |archive-url=https://web.archive.org/web/20210305153214/https://www.python.org/dev/peps/pep-0623/ |archive-date=5 March 2021 |access-date=2021-02-14 |website=Python.org |language=en}}
Python 3.13 introduces some changes in behavior, i.e., new "well-defined semantics", fixing bugs, and removing many deprecated classes, functions and methods (as well as some of the Python/C API and outdated modules). "The old implementation of locals()
and frame.f_locals
was slow, inconsistent and buggy, and it had many corner cases and oddities. Code that works around those may need revising; code that uses locals()
for simple templating or print debugging should continue to work correctly."{{Cite web |title=PEP 667 – Consistent views of namespaces {{!}} peps.python.org |url=https://peps.python.org/pep-0667/ |access-date=2024-10-07 |website=Python Enhancement Proposals (PEPs) |language=en}}
Python 3.13 introduces the experimental free-threaded build mode, which disables the Global Interpreter Lock (GIL); the GIL is a feature of CPython that previously prevented multiple threads from executing Python bytecode simultaneously. This optional build, introduced through PEP 703, enables better exploitation of multi-core CPUs. By allowing multiple threads to run Python code in parallel, the free-threaded mode addresses long-standing performance bottlenecks associated with the GIL. This change offers a new path for parallelism in Python, without resorting to multiprocessing or external concurrency frameworks.{{Cite web |title=PEP 703 – Making the GIL Optional in CPython |url=https://peps.python.org/pep-0703/ |access-date=2025-03-30 |website=Python Enhancement Proposals (PEPs) |language=en}}
Regarding annotations in upcoming Python version: "In Python 3.14, from __future__ import annotations
will continue to work as it did before, converting annotations into strings."{{Cite web |title=PEP 749 – Implementing PEP 649 {{!}} peps.python.org |url=https://peps.python.org/pep-0749/ |access-date=2024-11-20 |website=Python Enhancement Proposals (PEPs) |language=en}}
Python 3.14 drops the PGP digital verification signatures, it had deprecated in version 3.11, when its replacement Sigstore was added for all CPython artifacts; the use of PGP has been criticized by security practitioners.{{Cite web |title=PEP 761 – Deprecating PGP signatures for CPython artifacts {{!}} peps.python.org |url=https://peps.python.org/pep-0761/ |access-date=2025-01-06 |website=Python Enhancement Proposals (PEPs) |language=en}}
Some additional standard-library modules will be removed in Python 3.15 or 3.16, as will be many deprecated classes, functions and methods.{{Cite web |last=Wouters |first=Thomas |date=2024-04-09 |title=Python Insider: Python 3.12.3 and 3.13.0a6 released |url=https://pythoninsider.blogspot.com/2024/04/python-3123-and-3130a6-released.html |access-date=2024-04-29 |website=Python Insider}}{{cite web |title=PEP 594 – Removing dead batteries from the standard library |url=https://peps.python.org/pep-0594/ |website=Python Enhancement Proposals |publisher=Python Software Foundation |date=20 May 2019}}
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 and metaobjects). Many other paradigms are supported via extensions, including design by contract and logic programming. Python is often referred to as a
Python uses dynamic typing and a combination of reference counting and a cycle-detecting garbage collector for memory management.{{Cite web |url=https://docs.python.org/extending/extending.html#reference-counts |title=Extending and Embedding the Python Interpreter: Reference Counts |publisher=Docs.python.org |language=en |access-date=5 June 2020 |quote=Since Python makes heavy use of malloc()
and free()
, it needs a strategy to avoid memory leaks as well as the use of freed memory. The chosen method is called reference counting. |archive-date=18 October 2012 |archive-url=https://web.archive.org/web/20121018063230/http://docs.python.org/extending/extending.html#reference-counts |url-status=live}} 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 {{codes|filter|map|reduce|d=and}} functions; list comprehensions, dictionaries, sets, and generator expressions. The standard library has two modules ({{codes|itertools}} and {{codes|functools}}) that implement functional tools borrowed from Haskell and Standard ML.
Python's core philosophy is summarized in the Zen of Python (PEP 20), which includes aphorisms such as these:
- Beautiful is better than ugly.
- Explicit is better than implicit.
- Simple is better than complex.
- Complex is better than complicated.
- Readability counts.
However, Python features regularly violate these principles and have received criticism for adding unnecessary language bloat.{{cite web |url=https://learning-python.com/python-changes-2014-plus.html |title=Python Changes 2014+ |last=Lutz |first=Mark |date=January 2022 |website=Learning Python |access-date=2024-02-25 |archive-date=15 March 2024 |archive-url=https://web.archive.org/web/20240315075935/https://learning-python.com/python-changes-2014-plus.html |url-status=live}} Responses to these criticisms note that the Zen of Python is a guideline rather than a rule.{{cite web |url=https://discuss.python.org/t/confusion-regarding-a-rule-in-the-zen-of-python/15927 |title=Confusion regarding a rule in The Zen of Python |author= |date=2022-05-03 |website=Python Help - Discussions on Python.org |access-date=2024-02-25 |archive-date=25 February 2024 |archive-url=https://web.archive.org/web/20240225221142/https://discuss.python.org/t/confusion-regarding-a-rule-in-the-zen-of-python/15927 |url-status=live}} 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 Python 3.8.{{cite web |url=https://pythonsimplified.com/the-most-controversial-python-walrus-operator/ |title=The Most Controversial Python Walrus Operator |last=Ambi |first=Chetan |date=2021-07-04 |website=Python Simplified |access-date=2024-02-05 |archive-date=27 August 2023 |archive-url=https://web.archive.org/web/20230827154931/https://pythonsimplified.com/the-most-controversial-python-walrus-operator/ |url-status=live}}{{cite web |url=https://therenegadecoder.com/code/the-controversy-behind-the-walrus-operator-in-python/ |title=The Controversy Behind The Walrus Operator in Python |last=Grifski |first=Jeremy |date=2020-05-24 |website=The Renegade Coder |access-date=2024-02-25 |archive-date=28 December 2023 |archive-url=https://web.archive.org/web/20231228135749/https://therenegadecoder.com/code/the-controversy-behind-the-walrus-operator-in-python/ |url-status=live}}
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. 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, for example, at least three ways to format a string literal, with no certainty as to which one a programmer should use.{{cite web |url=https://realpython.com/python-string-formatting/ |title=Python String Formatting Best Practices |last=Bader |first=Dan |website=Real Python |access-date=2024-02-25 |archive-date=18 February 2024 |archive-url=https://web.archive.org/web/20240218083506/https://realpython.com/python-string-formatting/ |url-status=live}} 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 usually try to avoid premature optimization; they also reject patches to non-critical parts of the CPython reference implementation that would offer marginal increases in speed at the cost of clarity. 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 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's developers aim for the language to be fun 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 "foo" and "bar".{{Cite web|url=https://insidetech.monster.com/training/articles/8114-15-ways-python-is-a-powerful-force-on-the-web|title=15 Ways Python Is a Powerful Force on the Web|access-date=3 July 2018|archive-date=11 May 2019|archive-url=https://web.archive.org/web/20190511065650/http://insidetech.monster.com/training/articles/8114-15-ways-python-is-a-powerful-force-on-the-web|url-status=dead}}{{Cite web |title=pprint – Data pretty printer – Python 3.11.0 documentation |url=https://docs.python.org/3/library/pprint.html |access-date=2022-11-05 |website=docs.python.org |quote=stuff=['spam', 'eggs', 'lumberjack', 'knights', 'ni'] |archive-date=22 January 2021 |archive-url=https://web.archive.org/web/20210122224848/https://docs.python.org/3/library/pprint.html |url-status=live}} 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.{{Cite web|url=https://docs.python-guide.org/writing/style|title=Code Style – The Hitchhiker's Guide to Python|website=docs.python-guide.org|access-date=20 January 2021|archive-date=27 January 2021|archive-url=https://web.archive.org/web/20210127154341/https://docs.python-guide.org/writing/style/|url-status=live}}
Syntax and semantics
{{Main|Python syntax and semantics}}
File:Hello World in Python.png
File:Af-Helloworld (C Sharp).svg code with curly braces and semicolons]]
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=
{{Main|Python syntax and semantics#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.{{Cite book |publisher=MIT Press |isbn=978-0-262-52962-4 |last=Guttag |first=John V. |title=Introduction to Computation and Programming Using Python: With Application to Understanding Data |date=12 August 2016}} 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.{{Cite web|url=https://www.python.org/dev/peps/pep-0008/|title=PEP 8 – Style Guide for Python Code|website=Python.org|access-date=26 March 2019|archive-date=17 April 2019|archive-url=https://web.archive.org/web/20190417223549/https://www.python.org/dev/peps/pep-0008/|url-status=live}}
=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 withelse
andelif
(a contraction ofelse if
) - The
for
statement, which iterates over an iterable object, capturing each element to a local variable for use by the attached block - The
while
statement, which executes a block of code as long as its condition is true - The
try
statement, which allows exceptions raised in its attached code block to be caught and handled byexcept
clauses (or new syntaxexcept*
in Python 3.11 for exception groups{{Cite web |title=8. Errors and Exceptions – Python 3.12.0a0 documentation |url=https://docs.python.org/3.11/tutorial/errors.html |access-date=2022-05-09 |website=docs.python.org |archive-date=9 May 2022 |archive-url=https://web.archive.org/web/20220509145745/https://docs.python.org/3.11/tutorial/errors.html |url-status=live}}); thetry
statement also ensures that clean-up code in afinally
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{{cite web|url=https://www.python.org/download/releases/2.5/highlights/|title=Highlights: Python 2.5|website=Python.org|access-date=20 March 2018|archive-date=4 August 2019|archive-url=https://web.archive.org/web/20190804120408/https://www.python.org/download/releases/2.5/highlights/|url-status=live}} 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 {{efn|del
in Python does not behave the same waydelete
in languages such as C++ does, where such a word is used to call the destructor and deallocate heap memory.}} - 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
andfrom
statements, used to import modules whose functions or variables can be used in the current program - The
match
andcase
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/
.{{cite web|title=division|url=https://docs.python.org|website=python.org|access-date=30 July 2014|archive-date=20 July 2006|archive-url=https://web.archive.org/web/20060720033244/http://docs.python.org/|url-status=live}} 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.{{cite web |title=PEP 0465 – A dedicated infix operator for matrix multiplication |url=https://www.python.org/dev/peps/pep-0465/ |website=python.org |access-date=1 January 2016 |archive-date=4 June 2020 |archive-url=https://web.archive.org/web/20200604224255/https://www.python.org/dev/peps/pep-0465/ |url-status=live}}{{cite web |title=Python 3.5.1 Release and Changelog |url=https://www.python.org/downloads/release/python-351/ |website=python.org |access-date=1 January 2016 |archive-date=14 May 2020 |archive-url=https://web.archive.org/web/20200514034938/https://www.python.org/downloads/release/python-351/ |url-status=live}} - The syntax
:=
, called the "walrus operator", was introduced in Python 3.8. This operator assigns values to variables as part of a larger expression.{{cite web |title=What's New in Python 3.8 |url=https://docs.python.org/3.8/whatsnew/3.8.html |access-date=14 October 2019 |archive-date=8 June 2020 |archive-url=https://web.archive.org/web/20200608124345/https://docs.python.org/3.8/whatsnew/3.8.html |url-status=live}} - In Python,
==
compares two objects by value. Python'sis
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 <= b <= c}}. - Python uses
and
,or
, andnot
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 {{code|lang=python|code=x if c else y}}. (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 {{code|lang=python|code=[1, 2, 3]}}, are mutable, and cannot be used as the keys of dictionaries (since dictionary keys must be immutable in Python). Tuples, written as {{code|lang=python|code=(1, 2, 3)}}, 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 variablet
initially equal to {{code|lang=python|code=(1, 2, 3)}}, executing {{code|lang=python|code=t = t + (4, 5)}} first evaluates {{code|lang=python|code=t + (4, 5)}}, which yields {{code|lang=python|code=(1, 2, 3, 4, 5)}}; this result is then assigned back tot
—thereby effectively "modifying the contents" oft
while conforming to the immutable nature of tuple objects. Parentheses are optional for tuples in unambiguous contexts.{{cite web|title=4. Built-in Types – Python 3.6.3rc1 documentation|url=https://docs.python.org/3/library/stdtypes.html#tuple|website=python.org|access-date=1 October 2017|archive-date=14 June 2020|archive-url=https://web.archive.org/web/20200614194325/https://docs.python.org/3/library/stdtypes.html#tuple|url-status=live}} - 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.{{cite web|title=5.3. Tuples and Sequences – Python 3.7.1rc2 documentation|url=https://docs.python.org/3/tutorial/datastructures.html#tuples-and-sequences|website=python.org|access-date=17 October 2018|archive-date=10 June 2020|archive-url=https://web.archive.org/web/20200610050047/https://docs.python.org/3/tutorial/datastructures.html#tuples-and-sequences|url-status=live}}
- Python has a "string format" operator
%
that functions analogously toprintf
format strings in the C language—e.g. {{code|2=python|1="spam=%s eggs=%d" % ("blah", 2)}} evaluates to"spam=blah eggs=2"
. In Python 2.6+ and 3+, this operator was supplemented by theformat()
method of thestr
class, e.g., {{code|2=python|1="spam={0} eggs={1}".format("blah", 2)}}. Python 3.6 added "f-strings": {{code|2=python|1=spam = "blah"; eggs = 2; f'spam={spam} eggs={eggs}'}}.{{cite web |title=PEP 498 – Literal String Interpolation |url=https://www.python.org/dev/peps/pep-0498/ |website=python.org |access-date=8 March 2017 |archive-date=15 June 2020 |archive-url=https://web.archive.org/web/20200615184141/https://www.python.org/dev/peps/pep-0498/ |url-status=live}} - Strings in Python can be concatenated by "adding" them (using the same operator as for adding integers and floats); e.g., {{code|2=python|1="spam" + "eggs"}} returns
"spameggs"
. If strings contain numbers, they are concatenated as strings rather than as integers, e.g. {{code|2=python|1="2" + "2"}} 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]
, {{code|lang=python|code=a[start:stop]}} or {{code|lang=python|code=a[start:stop:step]}}. 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, {{code|lang=python|code=a[:]}} 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 {{code|lang=python|code=a = 1}} cannot be part of the conditional expression of a conditional statement.
=Methods=
Methods of objects are functions attached to the object's class; the syntax for normal methods and functions, {{code|lang=python|code=instance.method(argument)}}, is syntactic sugar for {{code|lang=python|code=Class.method(instance, argument)}}. Python methods have an explicit self
parameter to access instance data, in contrast to the implicit self (or this
) parameter in some object-oriented programming languages (e.g., C++, Java, Objective-C, Ruby). Python also provides methods, often called dunder methods (because their names begin and end with double underscores); these methods allow user-defined classes to modify how they are handled by native operations including length, comparison, arithmetic, and type conversion.{{cite book |last1=Sweigart |first1=Al |title=Beyond the Basic Stuff with Python: Best Practices for Writing Clean Code |year=2020 |publisher=No Starch Press |isbn=978-1-59327-966-0 |page=322 |url=https://books.google.com/books?id=7GUKEAAAQBAJ&pg=PA322 |language=en |access-date=7 July 2021 |archive-date=13 August 2021 |archive-url=https://web.archive.org/web/20210813194312/https://books.google.com/books?id=7GUKEAAAQBAJ&pg=PA322 |url-status=live}}
=Typing=
File:Python 3.13 Standrd Type Hierarchy-en.svg
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, {{code|lang=python|code=SpamClass()}} or {{code|lang=python|code=EggsClass()}}); 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.{{Cite web |title=PEP 484 – Type Hints {{!}} peps.python.org |url=https://peps.python.org/pep-0484/ |access-date=2023-11-29 |website=peps.python.org |archive-date=27 November 2023 |archive-url=https://web.archive.org/web/20231127205023/https://peps.python.org/pep-0484/ |url-status=live}} These annotations are not enforced by the language, but may be used by external tools such as mypy to catch errors.{{cite web |title=typing — Support for type hints |url=https://docs.python.org/3/library/typing.html |website=Python documentation |publisher=Python Software Foundation |access-date=22 December 2023 |archive-date=21 February 2020 |archive-url=https://web.archive.org/web/20200221184042/https://docs.python.org/3/library/typing.html |url-status=live}}{{cite web |url=http://mypy-lang.org/ |title=mypy – Optional Static Typing for Python |access-date=28 January 2017 |archive-date=6 June 2020 |archive-url=https://web.archive.org/web/20200606192012/http://mypy-lang.org/ |url-status=live}} Mypy also supports a Python compiler called mypyc, which leverages type annotations for optimization.{{cite web |title=Introduction |url=https://mypyc.readthedocs.io/en/latest/introduction.html |website=mypyc.readthedocs.io |access-date=22 December 2023 |archive-date=22 December 2023 |archive-url=https://web.archive.org/web/20231222000457/https://mypyc.readthedocs.io/en/latest/introduction.html |url-status=live}}
class="wikitable"
|+ Summary of Python 3's built-in types |
Type
! Description ! Syntax examples |
---|
bool
| immutable | {{code|lang=python|True}} |
bytearray
| mutable | Sequence of bytes | {{code|lang=python|bytearray(b'Some ASCII')}} |
bytes
| immutable | Sequence of bytes | {{code|lang=python|b'Some ASCII'}} |
complex
| immutable | Complex number with real and imaginary parts | {{code|lang=python|3+2.7j}} |
dict
| mutable | Associative array (or dictionary) of key and value pairs; can contain mixed types (keys and values); keys must be a hashable type | {{code|lang=python|{'key1': 1.0, 3: False} }} |
types.EllipsisType
| immutable | An ellipsis placeholder to be used as an index in NumPy arrays | {{code|lang=python|...}} |
float
| immutable | Double-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 web |title=15. Floating Point Arithmetic: Issues and Limitations – Python 3.8.3 documentation |url=https://docs.python.org/3.8/tutorial/floatingpoint.html#representation-error |access-date=6 June 2020 |website=docs.python.org |quote=Almost all machines today (November 2000) use IEEE-754 floating point arithmetic, and almost all platforms map Python floats to IEEE-754 "double precision". |archive-date=6 June 2020 |archive-url=https://web.archive.org/web/20200606113842/https://docs.python.org/3.8/tutorial/floatingpoint.html#representation-error |url-status=live }} | {{code|lang=python|1.33333}} |
frozenset
| immutable | Unordered set, contains no duplicates; can contain mixed types, if hashable | {{nobr|{{code|lang=python|frozenset([4.0, 'string', True])}}}} |
int
| immutable | Integer of unlimited magnitude | {{code|lang=python|42}} |
list
| mutable | List, can contain mixed types | {{code|lang=python|[4.0, 'string', True]}} |
types.NoneType
| immutable | An object representing the absence of a value, often called null in other languages | {{code|lang=python|None}} |
types.NotImplementedType
| immutable | A placeholder that can be returned from overloaded operators to indicate unsupported operand types. | {{code|lang=python|NotImplemented}} |
range
| immutable | An immutable sequence of numbers, commonly used for iterating a specific number of times in | {{code|lang=python|range(−1, 10)}} |
set
| mutable | Unordered set, contains no duplicates; can contain mixed types, if hashable | {{code|lang=python| {4.0, 'string', True} }} |
str
| immutable | A character string: sequence of Unicode codepoints | {{code|lang=python|'Wikipedia'}} multiple lines""" Spanning multiple lines |
tuple
| immutable | Tuple, can contain mixed types | {{code|lang=python|(4.0, 'string', True)}} |
=Arithmetic operations=
Python includes conventional symbols for arithmetic operators (+
, -
, *
, /
), the floor-division operator //
, and the modulo operator %
. (With the module operator, a remainder can be negative, e.g., 4 % -3 == -2
.) Python also offers the **
symbol for exponentiation, e.g. 5**3 == 125
and 9**0.5 == 3.0
; it also offers the matrix‑multiplication operator @
.{{cite web |url=https://legacy.python.org/dev/peps/pep-0465/ |title=PEP 465 – A dedicated infix operator for matrix multiplication |work=python.org |access-date=3 July 2018 |archive-date=29 May 2020 |archive-url=https://web.archive.org/web/20200529200310/https://legacy.python.org/dev/peps/pep-0465/ |url-status=live}} 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., {{code|class=nowrap|2=python|1=5/2 == 2.5}}. - The floor division
//
operator was introduced. Thus7//3 == 2
,-7//3 == -3
,7.5//3 == 2.0
, and-7.5//3 == -3.0
. For outdated Python 2.7 adding the {{code|class=nowrap|2=python2|1=from __future__ import division}} statement causes a module in Python 2.7 to use Python 3.0 rules for division instead (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 {{code|class=nowrap|2=python|1=(a + b)//b == a//b + 1}} is always true. The rounding also implies that the equation {{code|class=nowrap|2=python|1=b*(a//b) + a%b == a}} 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 < b < c
tests whether a
is less than b
and b
is less than c
. C-derived languages interpret this expression differently: in C, the expression would first evaluate a < b
, resulting in 0 or 1, and that result would then be compared with c
.
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.{{cite web|title=What's New in Python 2.6 |url=https://docs.python.org/2.6/whatsnew/2.6.html|website=Python v2.6.9 documentation |date=Oct 29, 2013 |access-date=26 September 2015|archive-date=23 December 2019|archive-url=https://web.archive.org/web/20191223213856/https://docs.python.org/2.6/whatsnew/2.6.html|url-status=live}}
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.{{Cite web|url=https://www.stat.washington.edu/~hoytak/blog/whypython.html|title=10 Reasons Python Rocks for Research (And a Few Reasons it Doesn't) – Hoyt Koepke|website=University of Washington Department of Statistics |access-date=3 February 2019|archive-date=31 May 2020|archive-url=https://web.archive.org/web/20200531211840/https://www.stat.washington.edu/~hoytak/blog/whypython.html|url-status=dead}}{{Cite web|url=https://engineering.ucsb.edu/~shell/che210d/python.pdf|title=An introduction to Python for scientific computing|last=Shell|first=Scott|date=17 June 2014|access-date=3 February 2019|archive-date=4 February 2019|archive-url=https://web.archive.org/web/20190204014642/https://engineering.ucsb.edu/~shell/che210d/python.pdf|url-status=live}}
=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
print('Hello, world!')
Program to calculate the factorial of a positive integer:
n = int(input('Type a number, and its factorial will be printed: '))
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)
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.
{{As of|2025|03|13|post=,}} the Python Package Index (PyPI), the official repository for third-party Python software, contains over 614,339{{cite web |date=2025-03-13 |title=PyPI |url=https://pypi.org/ |url-status=live |archive-url=https://web.archive.org/web/20250222013445/https://pypi.org/ |archive-date=2025-02-22 |website=PyPI}} packages. These have a wide range of functionality, including the following:
{{columns-list|colwidth=30em|
- Automation
- Data analytics
- Databases
- Documentation
- Graphical user interfaces
- Image processing
- Machine learning
- Mobile apps
- Multimedia
- Computer networking
- Scientific computing
- System administration
- Test frameworks
- Text processing
- Web frameworks
- Web scraping
}}
Development environments
{{See also|Comparison of integrated development environments#Python}}
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.
Python is also 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, IntelliJ Idea, Visual Studio Code; there are also web browser-based IDEs, such as the following environments:
- SageMath, for developing science- and math-related programs;
- Jupyter Notebooks, an open-source interactive computing platform;
- PythonAnywhere, a browser-based IDE and hosting environment; and
- Canopy IDE, a commercial IDE that emphasizes scientific computing.{{cite web|last1=Enthought|first1=Canopy|title=Canopy|url=https://www.enthought.com/products/canopy/|website=www.enthought.com|access-date=20 August 2016|archive-date=15 July 2017|archive-url=https://web.archive.org/web/20170715151703/https://www.enthought.com/products/canopy/|url-status=dead}}{{cite web |title=Project Jupyter |url=https://jupyter.org |website=Jupyter.org |access-date=2 April 2025 |archive-date=12 October 2023 |archive-url=https://web.archive.org/web/20231012055917/https://jupyter.org/ |url-status=live}}
Implementations
{{See also|List of Python software#Python implementations}}
=Reference implementation=
CPython is the reference implementation of Python. This implementation is written in C, meeting the C11 standard{{Cite web |title=PEP 7 – Style Guide for C Code {{!}} peps.python.org |url=https://peps.python.org/pep-0007/ |access-date=2022-04-28 |website=peps.python.org |archive-date=24 April 2022 |archive-url=https://web.archive.org/web/20220424202827/https://peps.python.org/pep-0007/ |url-status=live}} (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++.{{Cite web|title=4. Building C and C++ Extensions – Python 3.9.2 documentation|url=https://docs.python.org/3/extending/building.html|access-date=2021-03-01|website=docs.python.org|archive-date=3 March 2021|archive-url=https://web.archive.org/web/20210303002519/https://docs.python.org/3/extending/building.html|url-status=live}} 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;{{Cite web |title=Changelog – Python 3.9.0 documentation |url=https://docs.python.org/release/3.9.0/whatsnew/changelog.html#changelog |url-status=live |archive-url=https://web.archive.org/web/20210207001142/https://docs.python.org/release/3.9.0/whatsnew/changelog.html#changelog |archive-date=7 February 2021 |access-date=2021-02-08 |website=docs.python.org}}{{Cite web |title=Download Python |url=https://www.python.org/downloads/release/python-391 |url-status=live |archive-url=https://web.archive.org/web/20201208045225/https://www.python.org/downloads/release/python-391/ |archive-date=8 December 2020 |access-date=2020-12-13 |website=Python.org |language=en}} Windows XP was supported until Python 3.5, with unofficial support for VMS.{{Cite web|title=history [vmspython]|url=https://www.vmspython.org/doku.php?id=history|access-date=2020-12-04|website=www.vmspython.org|archive-date=2 December 2020|archive-url=https://web.archive.org/web/20201202194743/https://www.vmspython.org/doku.php?id=history|url-status=live}} Platform portability was one of Python's earliest priorities. During development of Python 1 and 2, even OS/2 and Solaris were supported;{{Cite web|title=Download Python for Other Platforms|url=https://www.python.org/download/other/|access-date=2020-12-04|website=Python.org|language=en|archive-date=27 November 2020|archive-url=https://web.archive.org/web/20201127015815/https://www.python.org/download/other/|url-status=live}} since that time, support has been dropped for many platforms.
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.
=Other implementations=
All alternative implementations have at least slightly different semantic. 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. Alternative implementations include the following:
- PyPy is a fast, compliant interpreter of Python 2.7 and 3.10.{{Cite web|last=Team|first=The PyPy|date=2019-12-28|title=Download and Install|url=https://www.pypy.org/download.html|access-date=2022-01-08|website=PyPy|language=en|archive-date=8 January 2022|archive-url=https://web.archive.org/web/20220108212951/https://www.pypy.org/download.html|url-status=live}} 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, for example.
- Codon is an implentation 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"{{Cite web |title=Codon: Differences with Python |url=https://docs.exaloop.io/codon/general/differences |url-status=live |archive-url=https://web.archive.org/web/20230525002540/https://docs.exaloop.io/codon/general/differences |archive-date=2023-05-25 |access-date=2023-08-28}} 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.{{Cite web |last=Lawson |first=Loraine |date=2023-03-14 |title=MIT-Created Compiler Speeds up Python Code |url=https://thenewstack.io/mit-created-compiler-speeds-up-python-code/ |url-status=live |archive-url=https://web.archive.org/web/20230406054200/https://thenewstack.io/mit-created-compiler-speeds-up-python-code/ |archive-date=2023-04-06 |access-date=2023-08-28 |website=The New Stack |language=en-US}} 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.{{Cite web|url=https://education.lego.com/en-us/support/mindstorms-ev3/python-for-ev3|title=Python-for-EV3|website=LEGO Education|language=en|access-date=17 April 2019|archive-date=7 June 2020|archive-url=https://web.archive.org/web/20200607234814/https://education.lego.com/en-us/support/mindstorms-ev3/python-for-ev3|url-status=live}}
- Pyston is a variant of the Python runtime that uses just-in-time compilation to speed up execution of Python programs.{{cite news|url=https://www.infoworld.com/article/3587591/pyston-returns-from-the-dead-to-speed-python.html|title=Pyston returns from the dead to speed Python|last=Yegulalp|first=Serdar|date=29 October 2020|website=InfoWorld|access-date=26 January 2021|archive-date=27 January 2021|archive-url=https://web.archive.org/web/20210127113233/https://www.infoworld.com/article/3587591/pyston-returns-from-the-dead-to-speed-python.html|url-status=live}}
- 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.{{Cite web|url=https://github.com/facebookincubator/cinder|title=cinder: Instagram's performance-oriented fork of CPython.|website=GitHub|access-date=4 May 2021|language=en|archive-date=4 May 2021|archive-url=https://web.archive.org/web/20210504112500/https://github.com/facebookincubator/cinder|url-status=live}}
- The Snek{{Cite web |last=Aroca |first=Rafael |date=2021-08-07 |title=Snek Lang: feels like Python on Arduinos |url=https://rafaelaroca.wordpress.com/2021/08/07/snek-lang-feels-like-python-on-arduinos/ |access-date=2024-01-04 |website=Yet Another Technology Blog |language=en |archive-date=5 January 2024 |archive-url=https://web.archive.org/web/20240105001031/https://rafaelaroca.wordpress.com/2021/08/07/snek-lang-feels-like-python-on-arduinos/ |url-status=live}}{{Cite web |last=Aufranc (CNXSoft) |first=Jean-Luc |date=2020-01-16 |title=Snekboard Controls LEGO Power Functions with CircuitPython or Snek Programming Languages (Crowdfunding) – CNX Software |url=https://www.cnx-software.com/2020/01/16/snekboard-controls-lego-power-functions-with-circuitpython-or-snek-programming-languages/ |access-date=2024-01-04 |website=CNX Software – Embedded Systems News |language=en-US |archive-date=5 January 2024 |archive-url=https://web.archive.org/web/20240105001031/https://www.cnx-software.com/2020/01/16/snekboard-controls-lego-power-functions-with-circuitpython-or-snek-programming-languages/ |url-status=live}}{{Cite web |last=Kennedy (@mkennedy) |first=Michael |title=Ready to find out if you're git famous? |url=https://pythonbytes.fm/episodes/show/187/ready-to-find-out-if-youre-git-famous |access-date=2024-01-04 |website=pythonbytes.fm |language=en-US |archive-date=5 January 2024 |archive-url=https://web.archive.org/web/20240105001031/https://pythonbytes.fm/episodes/show/187/ready-to-find-out-if-youre-git-famous |url-status=live}} 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."{{Cite web |last=Packard |first=Keith |date=2022-12-20 |title=The Snek Programming Language: A Python-inspired Embedded Computing Language |url=https://sneklang.org/doc/snek.pdf |access-date=4 January 2024 |archive-date=4 January 2024 |archive-url=https://web.archive.org/web/20240104162458/https://sneklang.org/doc/snek.pdf |url-status=live}} 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.{{cite web|title=Python on the Nokia N900|url=http://www.stochasticgeometry.ie/2010/04/29/python-on-the-nokia-n900/|website=Stochastic Geometry|date=29 April 2010|access-date=9 July 2015|archive-date=20 June 2019|archive-url=https://web.archive.org/web/20190620000053/http://www.stochasticgeometry.ie/2010/04/29/python-on-the-nokia-n900/|url-status=live}}
=Cross-compilers 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,{{Cite web|title=Brython|url=https://brython.info/|access-date=2021-01-21|website=brython.info|archive-date=3 August 2018|archive-url=https://web.archive.org/web/20180803065954/http://brython.info/|url-status=live}} Transcrypt,{{cite web|title=Transcrypt – Python in the browser|url=https://www.transcrypt.org|access-date=22 December 2020|website=transcrypt.org|language=en|archive-date=19 August 2018|archive-url=https://web.archive.org/web/20180819133303/http://www.transcrypt.org/|url-status=live}}{{Cite web|url=https://www.infoq.com/articles/transcrypt-python-javascript-compiler/|title=Transcrypt: Anatomy of a Python to JavaScript Compiler|website=InfoQ|access-date=20 January 2021|archive-date=5 December 2020|archive-url=https://web.archive.org/web/20201205193339/https://www.infoq.com/articles/transcrypt-python-javascript-compiler/|url-status=live}} and Pyjs compile Python to JavaScript. (The latest release of Pyjs was in 2012.)
- 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".{{Cite web|title=Transpiling Python to Julia using PyJL|url=https://web.ist.utl.pt/antonio.menezes.leitao/ADA/documents/publications_docs/2022_TranspilingPythonToJuliaUsingPyJL.pdf|quote=After manually modifying one line of code by specifying the necessary type information, we obtained a speedup of 52.6×, making the translated Julia code 19.5× faster than the original Python code.|access-date=20 September 2023|archive-date=19 November 2023|archive-url=https://web.archive.org/web/20231119071525/https://web.ist.utl.pt/antonio.menezes.leitao/ADA/documents/publications_docs/2022_TranspilingPythonToJuliaUsingPyJL.pdf|url-status=live}} 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.{{cite web|title=Nuitka Home {{!}} Nuitka Home|url=http://nuitka.net/|access-date=18 August 2017|website=nuitka.net|language=en|archive-date=30 May 2020|archive-url=https://web.archive.org/web/20200530211233/https://nuitka.net/|url-status=live}} This compiler works with Python 3.4 to 3.12 (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).{{cite journal |last1=Guelton |first1=Serge |last2=Brunet |first2=Pierrick |last3=Amini |first3=Mehdi |last4=Merlini |first4=Adrien |last5=Corbillon |first5=Xavier |last6=Raynaud |first6=Alan |title=Pythran: enabling static optimization of scientific Python programs |journal=Computational Science & Discovery |publisher=IOP Publishing |volume=8 |issue=1 |date=16 March 2015 |issn=1749-4699 |doi=10.1088/1749-4680/8/1/014001|doi-access=free |page=014001 |bibcode=2015CS&D....8a4001G}}
- RPython can be compiled to C, and it is used to build the PyPy interpreter for Python.
- The Python → 11l → C++ transpiler{{Cite web |url=https://11l-lang.org/transpiler |title=The Python → 11l → C++ transpiler |access-date=17 July 2022 |archive-date=24 September 2022 |archive-url=https://web.archive.org/web/20220924233728/https://11l-lang.org/transpiler/ |url-status=live}} 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.{{Cite web|url=https://github.com/google/grumpy|title=google/grumpy|date=10 April 2020|via=GitHub|access-date=25 March 2020|archive-date=15 April 2020|archive-url=https://web.archive.org/web/20200415054919/https://github.com/google/grumpy|url-status=live}}{{Cite web|url=https://opensource.google/projects/|title=Projects|website=opensource.google|access-date=25 March 2020|archive-date=24 April 2020|archive-url=https://web.archive.org/web/20200424191248/https://opensource.google/projects/|url-status=live}}{{Cite news|url=https://www.theregister.com/2017/01/05/googles_grumpy_makes_python_go/|title=Google's Grumpy code makes Python Go|first=Thomas Claburn in San|last=Francisco|website=www.theregister.com|access-date=20 January 2021|archive-date=7 March 2021|archive-url=https://web.archive.org/web/20210307165521/https://www.theregister.com/2017/01/05/googles_grumpy_makes_python_go/|url-status=live}} The latest release was in 2017.
- IronPython allows running Python 2.7 programs with the .NET Common Language Runtime.{{Cite web|title=IronPython.net /|url=https://ironpython.net/|website=ironpython.net|archive-date=17 April 2021|archive-url=https://web.archive.org/web/20210417064418/https://ironpython.net/|url-status=live}} An alpha version (released in 2021), is available for "Python 3.4, although features and behaviors from later versions may be included."{{Cite web |url=https://github.com/IronLanguages/ironpython3 |title=GitHub – IronLanguages/ironpython3: Implementation of Python 3.x for .NET Framework that is built on top of the Dynamic Language Runtime |website=GitHub |archive-date=28 September 2021 |archive-url=https://web.archive.org/web/20210928101250/https://github.com/IronLanguages/ironpython3 |url-status=live}}
- Jython compiles Python 2.7 to Java bytecode, allowing the use of Java libraries from a Python program.{{Cite web|title=Jython FAQ|url=https://www.jython.org/jython-old-sites/archive/22/userfaq.html|access-date=2021-04-22|website=www.jython.org|archive-date=22 April 2021|archive-url=https://web.archive.org/web/20210422055726/https://www.jython.org/jython-old-sites/archive/22/userfaq.html|url-status=live}}
- Pyrex (last released in 2010) and Shed Skin (last released in 2013) compile to C and C++ respectively.
=Performance=
A perforance comparison among various Python implementations, using a non-numerical (combinatorial) workload, was presented at EuroSciPy '13.{{cite conference |title=Performance of Python runtimes on a non-numeric scientific code |last=Murri |first=Riccardo |conference=European Conference on Python in Science (EuroSciPy) |year=2013 |arxiv=1404.6388|bibcode=2014arXiv1404.6388M}} In addition, Python's performance relative to other programming languages is benchmarked by The Computer Language Benchmarks Game.{{cite web|title=The Computer Language Benchmarks Game|url=https://benchmarksgame-team.pages.debian.net/benchmarksgame/fastest/python.html|access-date=30 April 2020|archive-date=14 June 2020|archive-url=https://web.archive.org/web/20200614210246/https://benchmarksgame-team.pages.debian.net/benchmarksgame/fastest/python.html|url-status=live}}
There are several approaches to optimizing Python performance, given the inherent slowness of an interpreted language. These approaches include the following strategies or tools:
- Just-in-time compilation: Dynamically compiling Python code just before it is executed. This technique is used in libraries such as Numba and PyPy.
- Static compilation: Python code is 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, ordeque
fromcollections
for queue operations.
Language Development
Python's development is conducted largely 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.{{cite web|url=https://www.python.org/dev/peps/pep-0008/|title=PEP 8 – Style Guide for Python Code|website=Python.org|access-date=26 March 2019|archive-date=17 April 2019|archive-url=https://web.archive.org/web/20190417223549/https://www.python.org/dev/peps/pep-0008/|url-status=live}} 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.{{cite web |url=https://lwn.net/Articles/885854/ |title=Moving Python's bugs to GitHub [LWN.net] |access-date=2 October 2022 |archive-date=2 October 2022 |archive-url=https://web.archive.org/web/20221002183818/https://lwn.net/Articles/885854/ |url-status=live}} Development originally took place on a self-hosted source-code repository running Mercurial, until Python moved to GitHub in January 2017.{{Cite web|url=https://devguide.python.org/|title=Python Developer's Guide – Python Developer's Guide|website=devguide.python.org|access-date=17 December 2019|archive-date=9 November 2020|archive-url=https://web.archive.org/web/20201109032501/https://devguide.python.org/|url-status=live}}
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.{{Cite web |last=Hughes |first=Owen |date=2021-05-24 |title=Programming languages: Why Python 4.0 might never arrive, according to its creator |url=https://www.techrepublic.com/article/programming-languages-why-python-4-0-will-probably-never-arrive-according-to-its-creator/ |access-date=2022-05-16 |website=TechRepublic |language=en-US |archive-date=14 July 2022 |archive-url=https://web.archive.org/web/20220714201302/https://www.techrepublic.com/article/programming-languages-why-python-4-0-will-probably-never-arrive-according-to-its-creator/ |url-status=live}}
- 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.{{Cite web|url=https://www.python.org/dev/peps/pep-0602/|title=PEP 602 – Annual Release Cycle for Python|website=Python.org|language=en|access-date=6 November 2019|archive-date=14 June 2020|archive-url=https://web.archive.org/web/20200614202755/https://www.python.org/dev/peps/pep-0602/|url-status=live}}{{Cite web|url=https://lwn.net/Articles/802777/|title=Changing the Python release cadence [LWN.net]|website=lwn.net|access-date=6 November 2019|archive-date=6 November 2019|archive-url=https://web.archive.org/web/20191106170153/https://lwn.net/Articles/802777/|url-status=live}} 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. There are also special Python mentoring programs, such as PyLadies.
API documentation generators
Tools that can generate documentation for Python API include pydoc (available as part of the standard library); Sphinx; and Pdoc and its forks, Doxygen and Graphviz.{{Cite web |title=Documentation Tools |url=https://wiki.python.org/moin/DocumentationTools |access-date=2021-03-22 |website=Python.org |language=en |archive-date=11 November 2020 |archive-url=https://web.archive.org/web/20201111173635/https://wiki.python.org/moin/DocumentationTools |url-status=live}}
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. The official Python documentation also contains various references to Monty Python routines.{{cite book |last1=Lutz |first1=Mark |title=Learning Python: Powerful Object-Oriented Programming |year=2009 |publisher=O'Reilly Media, Inc. |isbn=9781449379322 |page=17 |url=https://books.google.com/books?id=1HxWGezDZcgC&pg=PA17 |language=en |access-date=9 May 2017 |archive-date=17 July 2017 |archive-url=https://web.archive.org/web/20170717044012/https://books.google.com/books?id=1HxWGezDZcgC&pg=PA17 |url-status=live}}{{cite book |last1=Fehily |first1=Chris |title=Python |year=2002 |publisher=Peachpit Press |isbn=9780201748840 |page=xv |url=https://books.google.com/books?id=carqdIdfVlYC&pg=PR15 |language=en |access-date=9 May 2017 |archive-date=17 July 2017 |archive-url=https://web.archive.org/web/20170717044040/https://books.google.com/books?id=carqdIdfVlYC&pg=PR15 |url-status=live}} Python users are sometimes referred to as "Pythonistas".{{Cite book |publisher=Sebastopol, CA : O'Reilly Media |isbn=978-1-4493-5936-2 |last=Lubanovic |first=Bill |title=Introducing Python |access-date=2023-07-31 |date=2014 |url=http://archive.org/details/introducingpytho0000luba |page=305}}
The affix Py is often used when naming Python applications or libraries. Some examples include the following:
Popularity
Since 2003, Python has consistently ranked in the top ten of the most popular programming languages in the TIOBE Programming Community Index; {{as of|2022|12|lc=y}}, Python was the most popular language. Python 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|lc=true}}{{Cite web|last=Blake|first=Troy|date=2021-01-18|title=TIOBE Index for January 2021|url=https://seniordba.wordpress.com/2021/01/18/tiobe-index-for-january-2021/|access-date=2021-02-26|website=Technology News and Information by SeniorDBA|language=en|archive-date=21 March 2021|archive-url=https://web.archive.org/web/20210321143253/https://seniordba.wordpress.com/2021/01/18/tiobe-index-for-january-2021/|url-status=live}}). In the TIOBE Index, monthly rankings are based on the volume of searches for programming languages on Google, Amazon, Wikipedia, Bing, and 20 other platforms. According to the accompanying graph, Python has shown a marked upward trend since the early 2000s, eventually passing more established languages such as C, C++, and Java. This trend can be attributed to Python's readable syntax, comprehensive standard library, and application in data science and machine learning fields.{{Cite web |title=TIOBE Index |url=https://www.tiobe.com/tiobe-index/ |access-date=2025-03-31 |website=TIOBE |language=en-US}}
Large organizations that use Python include Wikipedia, Google, Yahoo!, CERN, NASA, Facebook,{{Cite web|url=https://developers.facebook.com/blog/post/301|title=Tornado: Facebook's Real-Time Web Framework for Python – Facebook for Developers|website=Facebook for Developers|language=en-US|access-date=19 June 2018|archive-date=19 February 2019|archive-url=https://web.archive.org/web/20190219031313/https://developers.facebook.com/blog/post/301|url-status=live}} Amazon, Instagram,{{cite web |url=https://instagram-engineering.com/what-powers-instagram-hundreds-of-instances-dozens-of-technologies-adf2e22da2ad |title=What Powers Instagram: Hundreds of Instances, Dozens of Technologies |date=11 December 2016 |publisher=Instagram Engineering |access-date=27 May 2019 |archive-date=15 June 2020 |archive-url=https://web.archive.org/web/20200615183410/https://instagram-engineering.com/what-powers-instagram-hundreds-of-instances-dozens-of-technologies-adf2e22da2ad |url-status=live}} Spotify,{{Cite web|url=https://labs.spotify.com/2013/03/20/how-we-use-python-at-spotify/|title=How we use Python at Spotify|website=Spotify Labs|language=en-US|access-date=25 July 2018|date=20 March 2013|archive-date=10 June 2020|archive-url=https://web.archive.org/web/20200610005143/https://labs.spotify.com/2013/03/20/how-we-use-python-at-spotify/|url-status=live}} and some smaller entities such as Industrial Light & Magic and ITA. The social news networking site Reddit was developed mostly in Python.{{Citation|title=GitHub – reddit-archive/reddit: historical code from reddit.com.|url=https://github.com/reddit-archive/reddit|publisher=The Reddit Archives|access-date=20 March 2019|archive-date=1 June 2020|archive-url=https://web.archive.org/web/20200601104939/https://github.com/reddit-archive/reddit|url-status=live}} Organizations that partly use Python include Discord{{cite web | url=https://elixir-lang.org/blog/2020/10/08/real-time-communication-at-scale-with-elixir-at-discord/ | title=Real time communication at scale with Elixir at Discord | date=8 October 2020 }} and Baidu.{{cite web | url=https://www.freelancinggig.com/blog/2018/07/05/what-programming-language-is-baidu-built-in/#:~:text=Even%20though%20Baidu%20has%20used,part%20JavaScript%20has%20been%20applied | title=What Programming Language is Baidu Built In? | date=5 July 2018 }}
Types of Use
{{Main|List of Python software}}
Python has many uses, including the following:
- Scripting for web applications
- Scientific computing
- Artificial-intelligence and machine-learning projects
- Graphical user interfaces and desktop environments
- Embedded scripting in software and hardware products
- Operating systems
- Information security
Python can serve as a scripting language for web applications, e.g., via the {{Not a typo|mod_wsgi}} module for the Apache web server. With Web Server Gateway Interface, a standard API has evolved to facilitate these applications. Web frameworks such as Django, Pylons, Pyramid, TurboGears, web2py, Tornado, Flask, Bottle, and Zope support developers in the design and maintenance of complex applications. Pyjs and IronPython can be used to develop the client-side of Ajax-based applications. SQLAlchemy can be used as a data mapper to a relational database. Twisted is a framework to program communication between computers; this framework is used by Dropbox, for example.
Libraries such as NumPy, SciPy and Matplotlib allow the effective use of Python in scientific computing,{{cite journal |last=Oliphant |first=Travis |title=Python for Scientific Computing |journal=Computing in Science and Engineering |volume=9 |issue=3 |pages=10–20 |year=2007 |url=https://www.h2desk.com/blog/python-scientific-computing/ |doi=10.1109/MCSE.2007.58 |citeseerx=10.1.1.474.6460 |bibcode=2007CSE.....9c..10O |s2cid=206457124 |access-date=10 April 2015 |archive-date=15 June 2020 |archive-url=https://web.archive.org/web/20200615193226/https://www.h2desk.com/blog/python-scientific-computing/ |url-status=live| issn=1521-9615 }}{{cite journal |first1=K. Jarrod |last1=Millman |first2=Michael |last2=Aivazis |title=Python for Scientists and Engineers |journal=Computing in Science and Engineering |volume=13 |number=2 |pages=9–12 |year=2011 |url=http://www.computer.org/csdl/mags/cs/2011/02/mcs2011020009.html |doi=10.1109/MCSE.2011.36 |bibcode=2011CSE....13b...9M |access-date=7 July 2014 |archive-date=19 February 2019 |archive-url=https://web.archive.org/web/20190219031439/https://www.computer.org/csdl/mags/cs/2011/02/mcs2011020009.html |url-status=live}} with specialized libraries such as Biopython and Astropy providing domain-specific functionality. SageMath is a computer algebra system with a notebook interface that is programmable in Python; the SageMath library covers many aspects of mathematics, including algebra, combinatorics, numerical mathematics, number theory, and calculus.{{Citation|title=Science education with SageMath|url=http://visual.icse.us.edu.pl/methodology/why_Sage.html|publisher=Innovative Computing in Science Education|access-date=22 April 2019|archive-date=15 June 2020|archive-url=https://web.archive.org/web/20200615180428/http://visual.icse.us.edu.pl/methodology/why_Sage.html|url-status=dead}} OpenCV has Python bindings with a rich set of features for computer vision and image processing.{{Cite web|title=OpenCV: OpenCV-Python Tutorials|url=https://docs.opencv.org/3.4.9/d6/d00/tutorial_py_root.html|access-date=2020-09-14|website=docs.opencv.org|archive-date=23 September 2020|archive-url=https://web.archive.org/web/20200923063145/https://docs.opencv.org/3.4.9/d6/d00/tutorial_py_root.html|url-status=live}}
Python is commonly used in artificial-intelligence and machine-learning projects, with support from libraries such as TensorFlow, Keras, Pytorch, scikit-learn and ProbLog (a logic language).{{cite web |last1=Dean |first1=Jeff |last2=Monga |first2=Rajat |first3=Sanjay |last3=Ghemawat |display-authors=2 |author-link1=Jeff Dean (computer scientist) |title=TensorFlow: Large-scale machine learning on heterogeneous systems |url=http://download.tensorflow.org/paper/whitepaper2015.pdf |website=TensorFlow.org |publisher=Google Research |access-date=10 November 2015 |date=9 November 2015 |archive-date=20 November 2015 |archive-url=https://web.archive.org/web/20151120004649/http://download.tensorflow.org/paper/whitepaper2015.pdf |url-status=live}}{{cite web |last1=Piatetsky |first1=Gregory |title=Python eats away at R: Top Software for Analytics, Data Science, Machine Learning in 2018: Trends and Analysis |url=https://www.kdnuggets.com/2018/05/poll-tools-analytics-data-science-machine-learning-results.html/2 |website=KDnuggets |access-date=30 May 2018 |archive-date=15 November 2019 |archive-url=https://web.archive.org/web/20191115234216/https://www.kdnuggets.com/2018/05/poll-tools-analytics-data-science-machine-learning-results.html/2 |url-status=live}}{{cite web|url=https://scikit-learn.org/stable/testimonials/testimonials.html|title=Who is using scikit-learn? – scikit-learn 0.20.1 documentation|website=scikit-learn.org|access-date=30 November 2018|archive-date=6 May 2020|archive-url=https://web.archive.org/web/20200506210716/https://scikit-learn.org/stable/testimonials/testimonials.html|url-status=live}}{{cite web |author-link1=Norman Jouppi |last1=Jouppi |first1=Norm |title=Google supercharges machine learning tasks with TPU custom chip |url=https://cloudplatform.googleblog.com/2016/05/Google-supercharges-machine-learning-tasks-with-custom-chip.html |website=Google Cloud Platform Blog |access-date=19 May 2016 |archive-date=18 May 2016 |archive-url=https://web.archive.org/web/20160518201516/https://cloudplatform.googleblog.com/2016/05/Google-supercharges-machine-learning-tasks-with-custom-chip.html |url-status=live}}{{cite journal |last1=De Raedt |first1=Luc |last2=Kimmig|first2=Angelika |title=Probabilistic (logic) programming concepts |journal=Machine Learning |date=2015 |volume=100 |number=1 |pages=5–47 |doi=10.1007/s10994-015-5494-z |s2cid=3166992 |doi-access=free}} As a scripting language with a modular architecture, simple syntax, and rich text processing tools, Python is often used for natural language processing.
The combination of Python and Prolog has proven useful for AI applications, with Prolog providing knowledge representation and reasoning capabilities. The Janus system, in particular, exploits similarities between these two languages, in part because of their dynamic typing and their simple, recursive data structures. This combination is typically applied natural language processing, visual query answering, geospatial reasoning, and handling semantic web data.Andersen, C. and Swift, T., 2023. The Janus System: a bridge to new prolog applications. In Prolog: The Next 50 Years (pp. 93–104). Cham: Springer Nature Switzerland.{{Cite web |title=SWI-Prolog Python interface |url=https://www.swi-prolog.org/pldoc/doc_for?object=section(%27packages/janus.html%27) |access-date=2024-03-15 |language=en-US |archive-date=15 March 2024 |archive-url=https://web.archive.org/web/20240315162046/https://www.swi-prolog.org/pldoc/doc_for?object=section%28%27packages%2Fjanus.html%27%29 |url-status=live}}
The Natlog system, implemented in Python, uses Definite Clause Grammars (DCGs) to create prompts for two types of generators: text-to-text generators such as GPT3, and text-to-image generators such as DALL-E or Stable Diffusion.Tarau, P., 2023. Reflections on automation, learnability and expressiveness in logic-based programming languages. In Prolog: The Next 50 Years (pp. 359–371). Cham: Springer Nature Switzerland.
Python can be used for graphical user interfaces (GUIs), by using libraries such as Tkinter.{{cite web |url=https://docs.python.org/3/library/tkinter.html |title=Tkinter — Python interface to TCL/Tk |access-date=9 June 2023 |archive-date=18 October 2012 |archive-url=https://web.archive.org/web/20121018043136/http://docs.python.org/library/tkinter.html |url-status=live}} Similarly, for the One Laptop per Child XO computer, most of the Sugar desktop environment is written in Python (as of 2008).{{cite web |url=https://www.geeksforgeeks.org/python-tkinter-tutorial/ |title=Python Tkinter Tutorial |date=3 June 2020 |access-date=9 June 2023 |archive-date=9 June 2023 |archive-url=https://web.archive.org/web/20230609031631/https://www.geeksforgeeks.org/python-tkinter-tutorial/ |url-status=live}}
Python is embedded in many software products (and some hardware products) as a scripting language. These products include the following:
- finite element method software such as Abaqus,
- 3D parametric modelers such as FreeCAD,
- 3D animation packages such as 3ds Max, Blender, Cinema 4D, Lightwave, Houdini, Maya, modo, MotionBuilder, Softimage,
- the visual effects compositor Nuke,
- 2D imaging programs such as GIMP,{{cite web |url=http://gimp-win.sourceforge.net/faq.html |title=Installers for GIMP for Windows – Frequently Asked Questions |author= |date=26 July 2013 |access-date=26 July 2013 |url-status=dead |archive-url=https://web.archive.org/web/20130717070814/http://gimp-win.sourceforge.net/faq.html |archive-date=17 July 2013}} Inkscape, Scribus and Paint Shop Pro, and
- musical notation programs such as scorewriter and capella.
Similarly, GNU Debugger uses Python as a pretty printer to show complex structures such as C++ containers. Esri promotes Python as the best choice for writing scripts in ArcGIS. Python has also been used in several video games, and it has been adopted as first of the three programming languages available in Google App Engine (the other two being Java and Go). LibreOffice includes Python, and its developers plan to replace Java with Python; LibreOffice's Python Scripting Provider is a core feature{{cite web |year=2013 |title=4.0 New Features and Fixes |url=http://www.libreoffice.org/download/4-0-new-features-and-fixes/ |url-status=live |archive-url=https://web.archive.org/web/20140209184807/http://www.libreoffice.org/download/4-0-new-features-and-fixes/ |archive-date=9 February 2014 |access-date=25 February 2013 |work=LibreOffice.org |publisher=The Document Foundation}} since version 4.0 (from 7 February 2013).
Among hardware products, the Raspberry Pi single-board computer project has adopted Python as its main user-programming language.
Many operating systems include Python as a standard component. Python ships with most Linux distributions,{{Cite web|url=https://docs.python.org/3/using/unix.html|title=Python Setup and Usage|publisher=Python Software Foundation|access-date=10 January 2020|archive-date=17 June 2020|archive-url=https://web.archive.org/web/20200617143505/https://docs.python.org/3/using/unix.html|url-status=live}} AmigaOS 4 (using Python 2.7), FreeBSD (as a package), NetBSD, and OpenBSD (as a package); it can be used from the command line (terminal). Many Linux distributions use installers written in Python: Ubuntu uses the Ubiquity installer, while Red Hat Linux and Fedora Linux use the Anaconda installer. Gentoo Linux uses Python in its package management system, Portage.
Python is used extensively in the information security industry, including in exploit development.
Languages influenced by Python
Python's design and philosophy have influenced many other programming languages:
- Boo uses indentation, a similar syntax, and a similar object model.
- Cobra uses indentation and a similar syntax; its Acknowledgements document lists Python first among influencing languages.
- CoffeeScript, a programming language that cross-compiles to JavaScript, has a Python-inspired syntax.
- ECMAScript–JavaScript borrowed iterators and generators from Python.
- GDScript, a Python-like scripting language that is built in to the Godot game engine.{{Cite web|url=https://docs.godotengine.org/en/stable/about/faq.html|title=Frequently asked questions|website=Godot Engine documentation|access-date=10 May 2021|archive-date=28 April 2021|archive-url=https://web.archive.org/web/20210428053339/https://docs.godotengine.org/en/stable/about/faq.html|url-status=live}}
- Go is designed for "speed of working in a dynamic language like Python"; Go shares Python's syntax for slicing arrays.
- Groovy was motivated by a desire to incorporate the Python design philosophy into Java.
- Julia was designed to be "as usable for general programming as Python".{{cite web |title= Why We Created Julia |date= February 2012 |website= Julia website |url= https://julialang.org/blog/2012/02/why-we-created-julia |access-date= 5 June 2014 |quote= We want something as usable for general programming as Python [...] |archive-date= 2 May 2020 |archive-url= https://web.archive.org/web/20200502144010/https://julialang.org/blog/2012/02/why-we-created-julia/ |url-status= live}}
- Mojo is a non-strict{{Cite web |title=Modular Docs – Why Mojo |url=https://docs.modular.com/mojo/why-mojo.html |access-date=2023-05-05 |website=docs.modular.com |language=en |quote=Mojo as a member of the Python family [..] Embracing Python massively simplifies our design efforts, because most of the syntax is already specified. [..] we decided that the right long-term goal for Mojo is to provide a superset of Python (i.e. be compatible with existing programs) and to embrace the CPython immediately for long-tail ecosystem enablement. To a Python programmer, we expect and hope that Mojo will be immediately familiar, while also providing new tools for developing systems-level code that enable you to do things that Python falls back to C and C++ for. |archive-date=5 May 2023 |archive-url=https://web.archive.org/web/20230505083518/https://docs.modular.com/mojo/why-mojo.html |url-status=live}} superset of Python (e.g., omitting classes, and adding struct).{{Cite web |last=Spencer |first=Michael |title=What is Mojo Programming Language? |url=https://datasciencelearningcenter.substack.com/p/what-is-mojo-programming-language |access-date=2023-05-05 |website=datasciencelearningcenter.substack.com |date=4 May 2023 |language=en |archive-date=5 May 2023 |archive-url=https://web.archive.org/web/20230505090408/https://datasciencelearningcenter.substack.com/p/what-is-mojo-programming-language |url-status=live}}
- Nim uses indentation and a similar syntax.{{cite web |url=https://www.infoworld.com/article/3157745/application-development/nim-language-draws-from-best-of-python-rust-go-and-lisp.html |title=Nim language draws from best of Python, Rust, Go, and Lisp |first=Serdar |last=Yegulalp |date=16 January 2017 |website=InfoWorld |quote=Nim's syntax is strongly reminiscent of Python's, as it uses indented code blocks and some of the same syntax (such as the way if/elif/then/else blocks are constructed). |access-date=7 June 2020 |archive-date=13 October 2018 |archive-url=https://web.archive.org/web/20181013211847/https://www.infoworld.com/article/3157745/application-development/nim-language-draws-from-best-of-python-rust-go-and-lisp.html |url-status=live}}
- Ruby's creator, Yukihiro Matsumoto, said that "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."
- Swift, a programming language developed by Apple, has some Python-inspired syntax.{{cite web |url=http://nondot.org/sabre |title=Chris Lattner's Homepage |publisher=Chris Lattner |first=Chris |last=Lattner |author-link=Chris Lattner |date=3 June 2014 |access-date=3 June 2014 |quote=I started work on the Swift Programming Language in July of 2010. I implemented much of the basic language structure, with only a few people knowing of its existence. A few other (amazing) people started contributing in earnest late in 2011, and it became a major focus for the Apple Developer Tools group in July 2013 [...] drawing ideas from Objective-C, Rust, Haskell, Ruby, Python, C#, CLU, and far too many others to list. |archive-date=22 December 2015 |archive-url=https://web.archive.org/web/20151222150510/http://nondot.org/sabre/ |url-status=live}}
- Kotlin blends Python and Java features, which minimizes boilerplate code and enhances developer efficiency.{{Cite web |last=Jalan |first=Nishant Aanjaney |date=2022-11-10 |title=Programming in Kotlin |url=https://medium.com/codex/programming-in-kotlin-934bdb3659cf |access-date=2024-04-29 |website=CodeX |language=en}}
Python's development practices have also been emulated by other languages. For example, Python requires a document that describes the rationale and context for any language change; this document is known as a Python Enhancement Proposal or PEP. This practice is also used by the developers of Tcl, Erlang, and Swift.{{cite web |title=Swift Evolution Process |date=18 February 2020 |website=Swift Programming Language Evolution repository on GitHub |url=https://github.com/apple/swift-evolution/blob/master/process.md |access-date=27 April 2020 |archive-date=27 April 2020 |archive-url=https://web.archive.org/web/20200427182556/https://github.com/apple/swift-evolution/blob/master/process.md |url-status=live}}
See also
{{Portal|Computer programming|Free and open-source software}}
- Python syntax and semantics
- pip (package manager)
- List of programming languages
- History of programming languages
- Comparison of programming languages
{{Clear}}
Notes
{{Notelist}}
References
{{Reflist|30em|refs=
{{cite book |url=http://shop.oreilly.com/product/9780596007973.do |title=Python Cookbook, 2nd Edition |publisher=O'Reilly Media |last1=Martelli |first1=Alex |last2=Ravenscroft |first2=Anna |last3=Ascher |first3=David |year=2005 |page=230 |isbn=978-0-596-00797-3 |access-date=14 November 2015 |archive-date=23 February 2020 |archive-url=https://web.archive.org/web/20200223171254/http://shop.oreilly.com/product/9780596007973.do |url-status=live}}
{{cite web |url=https://stackoverflow.com/questions/5033906/in-python-should-i-use-else-after-a-return-in-an-if-block |title=In Python, should I use else after a return in an if block? |date=17 February 2011 |work=Stack Overflow |publisher=Stack Exchange |access-date=6 May 2011 |archive-date=20 June 2019 |archive-url=https://web.archive.org/web/20190620000050/https://stackoverflow.com/questions/5033906/in-python-should-i-use-else-after-a-return-in-an-if-block |url-status=live}}
{{cite web |url=http://community.eveonline.com/news/dev-blogs/stackless-python-2.7/ |title=Stackless Python 2.7 |publisher=CCP Games |date=24 August 2010 |author=CCP porkbelly |work=EVE Community Dev Blogs |quote=As you may know, EVE has at its core the programming language known as Stackless Python. |access-date=11 January 2014 |archive-date=11 January 2014 |archive-url=https://web.archive.org/web/20140111155537/http://community.eveonline.com/news/dev-blogs/stackless-python-2.7/ |url-status=live}}
{{cite web |url=http://www.2kgames.com/civ4/blog_03.htm |title=Modding Sid Meier's Civilization IV |last=Caudill |first=Barry |date=20 September 2005 |publisher=Firaxis Games |archive-url=https://web.archive.org/web/20101202164144/http://www.2kgames.com/civ4/blog_03.htm |archive-date=2 December 2010 |work=Sid Meier's Civilization IV Developer Blog |quote=we created three levels of tools ... The next level offers Python and XML support, letting modders with more experience manipulate the game world and everything in it. |url-status=dead}}
}}
=Sources=
- {{cite web |url=https://wiki.python.org/moin/PythonForArtificialIntelligence |title=Python for Artificial Intelligence |publisher=Python Wiki |date=19 July 2012 |access-date=3 December 2012 |url-status=dead |archive-url=https://web.archive.org/web/20121101045354/http://wiki.python.org/moin/PythonForArtificialIntelligence |archive-date=1 November 2012}}
- {{cite journal |editor-last=Paine |editor-first=Jocelyn |title=AI in Python |journal=AI Expert Newsletter |publisher=Amzi! |date=August 2005 |url=http://www.ainewsletter.com/newsletters/aix_0508.htm#python_ai_ai |access-date=11 February 2012 |archive-url=https://web.archive.org/web/20120326105810/http://www.ainewsletter.com/newsletters/aix_0508.htm#python_ai_ai |archive-date=26 March 2012 |url-status=dead}}
- {{cite web |url=https://pypi.python.org/pypi/PyAIML |title=PyAIML 0.8.5 : Python Package Index |publisher=Pypi.python.org |access-date=17 July 2013}}
- {{cite book |title=Artificial Intelligence: A Modern Approach |last1=Russell |first1=Stuart J. |author-link1=Stuart J. Russell |last2=Norvig |first2=Peter |author-link2=Peter Norvig |name-list-style=amp |edition=3rd |year=2009 |publisher=Prentice Hall |location=Upper Saddle River, NJ |isbn=978-0-13-604259-4}}
Further reading
- {{cite book |last=Downey |first=Allen |title=Think Python: How to Think Like a Computer Scientist |edition=3rd |date=July 2024 |publisher=O'Reilly Media |isbn=978-1098155438 |url=https://allendowney.github.io/ThinkPython/}}
- {{cite book |last=Lutz |first=Mark |title=Learning Python |publisher=O'Reilly Media |year=2013 |edition=5th |isbn=978-0-596-15806-4}}
- {{cite book |last=Summerfield |first=Mark |title=Programming in Python 3 |publisher=Addison-Wesley Professional|year=2009|edition=2nd|isbn=978-0-321-68056-3}}
- {{cite book |last=Ramalho |first=Luciano |title=Fluent Python |url=https://www.thoughtworks.com/insights/books/fluent-python-2nd-edition |date=May 2022 |publisher=O'Reilly Media |isbn=978-1-4920-5632-4}}
External links
{{Sister project links |wikt=no |display=Python |commons=Category:Python (programming language) |b=Python Programming |n=no |s=no |voy=no |species=no |d=Q28865}}
- {{Official website}}
- [https://docs.python.org/3/tutorial/ The Python Tutorial]
{{Python (programming language)|state=expanded}}
{{Programming languages}}
{{Python web frameworks}}
{{Differentiable computing}}
{{FOSS}}
{{Statistical software}}
{{Numerical analysis software}}
{{Authority control}}
Category:Articles with example Python (programming language) code
Category:Class-based programming languages
Category:Computer science in the Netherlands
Category:Concurrent programming languages
Category:Cross-platform free software
Category:Cross-platform software
Category:Dynamically typed programming languages
Category:Educational programming languages
Category:High-level programming languages
Category:Information technology in the Netherlands
Category:Multi-paradigm programming languages
Category:Object-oriented programming languages
Category:Pattern matching programming languages
Category:Programming languages
Category:Programming languages created in 1991