Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Python (programming language)
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==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]]<ref name="AutoNT-13"/> and [[metaobject]]s).<ref name="AutoNT-14"/> Many other paradigms are supported via extensions, including [[design by contract]]<ref name="AutoNT-15"/><ref name="AutoNT-16"/> and [[logic programming]].<ref name="AutoNT-17"/> Python is often referred to as a ''[[glue language|<nowiki/>'glue language]]'''<ref>{{Cite web |title=Glue It All Together With Python |url=https://www.python.org/doc/essays/omg-darpa-mcc-position/ |access-date=2024-09-30 |website=Python.org |language=en}}</ref> because it can seamlessly integrate components written in other languages. Python uses dynamic typing and a combination of [[reference counting]] and a cycle-detecting garbage collector for [[memory management]].<ref name="Reference_counting">{{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 <code>malloc()</code> and <code>free()</code>, 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}}</ref> It uses dynamic [[Name resolution (programming languages)|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 (programming language)|Lisp]] tradition. It has {{codes|filter|map|reduce|d=and}} functions; [[list comprehension]]s, [[Associative array|dictionaries]], sets, and [[generator (computer programming)|generator]] expressions.<ref name="AutoNT-59"/> The standard library has two modules ({{codes|itertools}} and {{codes|functools}}) that implement functional tools borrowed from [[Haskell]] and [[Standard ML]].<ref name="AutoNT-18"/> Python's core philosophy is summarized in the [[Zen of Python]] (PEP 20), which includes aphorisms such as these:<ref name="PEP20"/> <!-- Note this isn't a full list, just some of the more significant aphorisms --> * 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.<ref name="Python-Changes-2014">{{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}}</ref> Responses to these criticisms note that the Zen of Python is a guideline rather than a rule.<ref name="Confusion-regarding-a-rule-in-the-Zen-of-Python">{{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=<!--Not stated--> |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}}</ref> 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.<ref name="The-Most-Controversial-Python-Walrus-Operator">{{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}}</ref><ref name="The-Controversy-Behind-The-Walrus-Operator-in-Python">{{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}}</ref> 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.<ref name="venners-interview-pt-1"/> 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."<!-- the "—" spacing here, although inconsistent with Wikipedia MOS, is quoted text and must be maintained as is; do not "correct" it -->.<ref name="PEP20"/> 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.<ref name="Python-String-Formatting-Best-Practices">{{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}}</ref> [[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."<ref name="AutoNT-19"/> 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.<ref name="AutoNT-20"/> 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-compilers to other languages|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).<ref name=PyJL/> 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]]<ref name="whyname"/>—and in playful approaches to some tutorials and reference materials. For instance, some code examples use the terms "spam" and "eggs" (in reference to [[Spam (Monty Python)|a Monty Python sketch]]), rather than the typical terms [[foobar|"foo" and "bar"]].<ref>{{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}}</ref><ref>{{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}}</ref> 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 [[Programming idiom|idioms]] well; be natural or show fluency in the language; or conform with Python's minimalist philosophy and emphasis on readability.<ref>{{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}}</ref>
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)