Jump to content

Python (programming language)

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by 2605:940:511:2c00:: (talk) at 02:43, 4 June 2025 (Undid revision 1293860674 by Skynxnex (talk)). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

Template:Use dm dates {{Inobox programming language | logo = Pythonlogo-notext.svg | logo size = 15056px | paradigm = Multi-paradigm: object-oriented,[1] procedural (imperative), functional, [[Structured prdeveloper = Python Softwar Foundation |ionality. Python 3.12 added the new keyword type. Notable changes from version 3.10 to 3.11 include increased lds and such (and more) will be disallowed in Python 3.15. Python 3.12 removed wstr meaning Python extensions[2] need to be modified.[3]

Python 3.13 introduces some changes in behavior, i.e., new us standard library modules. C API removals and deprecation -->The old implementation of "In Python 3.14, from __future__ import annotations will continue to work as it did before, converting annotations into strings."Cite error: A <ref> tag is missing the closing </ref> (see the help page). 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.[4]

==Syntax and semet programming language|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.[5]

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.[6] Thus, the program's visual structure accurately represents its semantic structure.[7] 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.[8]

Statements and control flow

Python's statements include the following:

  • The assignment statement, using a single equals sign =
  • The if stement, which iterates over an iterable object, capturing each element to a local variable for use by the attached block
  • The [[While loop#Python|while]ent, 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 by except clauses (or new syntax except* in Python 3.11 for exception groups[9]); the try statement also ensures that clean-up code in a finally block is always run regardless of how the block exits
  • The raise statement, used to raise a specified exception or re-raise a caught exception
  • The class statement, which executes a block of code and attaches its local namespace to a class, for use in object-oriented programming
  • The def statement, which defines a function or [[method (computing)|method]
  • The pass statement, serving as a NOP (i.e., no operation), which is syntactically needed to create an empty code block
  • The [[assertion (programming)|assquently 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

Python does not support tail call optimization or first-class continuations; according to Van Rossum, the language never will.[10][11] However, better support for coroutine-like functionality is provided by extending Python's generators.[12] Before 2.5, generators were [[lazy evaluatid from version 3.3, data can be passed through multiple stack levels.Cite error: The <ref> tag has too many names (see the help page).

  • In Python, == compares two objects by value. Python's is operator may be used to compare object identities (i.e., comparison by reference), and comparisons may be chained—for example, a <= b <= c.
  • Python uses and, or, and not as Boolean operators.
  • Python has a type of expression called a list comprehension, and a more general expression called a generator expression.[13]
  • Anonymous functions are implemented using lambda expressions; however, there may be only one expression in each body.
  • Conditional expressions are written as x if c else y.[14] (This is different in operand order from the c ? x : y operator common to many other languages.)
  • Python makes a distinction between; this resng 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 exhe left.Cite error: A <ref> tag is missing the closing </ref> (see the help page). These annotations are not enforced by the language, but may be used by external tools such as mypy to catch errors.[15][16] Mypy also supports a Python compiler called mypyc, which leverages ty

! Synt | bool | immutable | Boolean value | True
False |- | bytearray | mutable | Sequence of | Sequence of bytes | b'Some ASCII'
b"Some ASCII"
bytes([119, 105, 107, 105])

| 3+2.7j
3
lann |- | float</codes and Limitations – Python

|websun

| An immutable sequence of numbers, commonly used for iterating a specific number of times in for loops[17] | range(1, 10)
range(10, 5, 2) |- | set | mutable | Unordered set, contains no duplicates; can contain mixed types, if hashable | {4.0, 'string', True}
set( </syntaxhighlight></ref> Outstanding PEPs are reviewed and commented on by the Python community and the steering council.[21]

Enhancement of the language corresponds with development of the CPython refes://lwn.net/Articles/885854/ |title=Moving Python's bugs to GitHub [LWN.net] |access-date=2 October 2022 |archive-datober 2022 |archive-url=https://web.archive.org/web/20221002183818/https://lwn.net/Articles/885854/ |url-status=live}}</ref> Development originally took place on a self-hosted source-code repository running Mercurial, until Python moved to GitHub in January 2017.[22]

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 releasety vulnerabilities are also patched in these releases. The third and final part of the version number is incremented.[23]

MfVlYC&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}}</ref> Python users are sometimes referred to as "Pythonistas".[24]

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 December 2022, Python was the most popular language.[25] Python was selected as Programming Language of the Year (for "the highest rise in ratings in a ye00/tutorial_py_root.html|url-status=live}}</ref>

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).[26]Cite error: A <ref> tag is missing the closing </ref> (see the help page).

  • Go is designed for "speed of working in a dynamic language like Python";[27] Go shares Python's syntax for s

[28]

[29]

[30]

[31]

[32]

[33]

[34]

[35]

[36]

[21]

[37]

[38]

[23]

[39]

[40]

[41]

[42]

[43]

[44]

[45]

[46]

[47]

[48]

[49]

[50]

[51]

[52]

[53]

[54]

[55]

[56]

[57]

[58]

[5]

[6]


[10]

[11]

[12]

[59]

[13]

[14]

[60]

[61]

[62]

[63]

[64]

[65]

[66]

[67]

[68]

[69]

[70]

[71]

[72]

[73]

[74]

[75]

[76]

[18]

[77]

[78]

[79]

[80]

[27]

[81]

[82]

[83]

[84]

[85]

}}

Sources

  • "Python for Artificial Intelligence". Python Wiki. 19 July 2012. Archived from the original on 1 November 2012. Retrieved 3 December 2012.
  • Paine, Jocelyn, ed. (August 2005). "AI in Python". AI Expert Newsletter. Amzi!. Archived from the original on 26 March 2012. Retrieved 11 February 2012.
  • "PyAIML 0.8.5 : Python Package Index". Pypi.python.org. Retrieved 17 July 2013.
  • Russell, Stuart J. & Norvig, Peter (2009). Artificial Intelligence: A Modern Approach (3rd ed.). Upper Saddle River, NJ: Prentice Hall. ISBN 978-0-13-604259-4.

Further reading

  1. ^ [https:/docs.pythn.org/3faq/general.html#what-is-python "General Python FAQ – Python 3 documentation"]. docs.python.org. Retrieved 2024-07-07. {{cite web}}: Check |url= value (help)
  2. ^ "1. Extending Python with C or C++ – Python 3.9.1 documentation". docs.python.org. Archived from the original on 23 June 2020. Retrieved 2021-02-14.
  3. ^ "PEP 623 – Remove wstr from Unicps:/python.org/dev/peps/pep-0623/". Python.org. {{cite web}}: |access-date= requires |url= (help); |archive-date= requires |archive-url= (help); Missing or empty |url= (help)
  4. ^ "Code Style – The Hitchhiker's Guide to Python". docs.python-guide.org. Archived from the original on 27 January 2021. Retrieved 20 January 2021.
  5. ^ a b "Is Python a good language for beginning programmers?". General Python FAQ. Python Software Foundation. Archived from the original on 24 October 2012. Retrieved 21 March 2007.
  6. ^ a b "Myths about indentation in Python". Secnetix.de. Archived from the original on 18 February 2018. Retrieved 19 April 2011.
  7. ^ Guttag, John V. (12 August 2016). Introduction to Computation and Programming Using Python: With Application to Understanding Data. MIT Press. ISBN 978-0-262-52962-4.
  8. ^ https://www.pyps/p://www.python.org/dev/peps/pep-0008/. {{cite web}}: Missing or empty |title= (help)CS1 maint: url-status (link)
  9. ^ "8. Errors and Exceptions – Python 3.12.0a0 documentation". docs.python.org. Archived from the original on 9 May 2022. Retrieved 2022-05-09.
  10. ^ a b van Rossum, Guido (22 April 2009). "Tail Recursion Elimination". Neopythonic.blogspot.be. Archived from the original on 19 May 2018. Retrieved 3 December 2012.
  11. ^ a b van Rossum, Guido (9 February 2006). "Language Design Is Not Just Solving Puzzles". Artima forums. Artima. Archived from the original on 17 January 2020. Retrieved 21 March 2007.
  12. ^ a b van Rossum, Guido; Eby, Phillip J. (10 May 2005). "PEP 342 – Coroutines via Enhanced Generators". Python Enhancement Proposals. Python Software Foundation. Archived from the original on 29 May 2020. Retrieved 19 February 2012.
  13. ^ a b Hettinger, Raymond (30 January 2002). "PEP 289 – Generator Expressions". Python Enhancement Proposals. Python Software Foundation. Archived from the original on 14 June 2020. Retrieved 19 February 2012.
  14. ^ a b van Rossum, Guido; Hettinger, Raymond (7 February 2003). "PEP 308 – Conditional Expressions". Python Enhancement Proposals. Python Software Foundation. Archived from the original on 13 March 2016. Retrieved 13 July 2011.
  15. ^ "typing — Support for type hints". Python documentation. Python Software Foundation. Archived from the original on 21 February 2020. Retrieved 22 December 2023.
  16. ^ "mypy – Optional Static Typing for Python". Archived from the original on 6 June 2020. Retrieved 28 January 2017.
  17. ^ "Built-in Types". Archived from the original on 14 June 2020. Retrieved 3 October 2019.
  18. ^ a b Batista, Facundo (17 October 2003). "PEP 327 – Decimal Data Type". Python Enhancement Proposals. Python Software Foundation. Archived from the original on 4 June 2020. Retrieved 24 November 2008.
  19. ^ "What's New in Python 2.6". Archived from Department of Statistics the original on 31 May 2020. Retrieved 3 February 2019. {{cite web}}: Check |url= value (help)
  20. ^ Shell, Scott (17 June 2014). "An introduction to Python for scientific computing" (PDF). Archived (PDF) from the original on 4 February 2019. Retrieved 3 February 2019.
  21. ^ a b Warsaw, Barry; Hylton, Jeremy; Goodger, David (13 June 2000). "PEP 1 – PEP Purpose and Guidelines". Python Enhancement Proposals. Python Software Foundation. Archived from the original on 6 June 2020. Retrieved 19 April 2011.
  22. ^ "Python Developer's Guide – Python Developer's Guide". devguide.python.org. Archived from the original on 9 November 2020. Retrieved 17 December 2019.
  23. ^ a b Aahz; Baxter, Anthony (15 March 2001). "PEP 6 – Bug Fix Releases". Python Enhancement Proposals. Python Software Foundation. Archived from the original on 5 June 2020. Retrieved 27 June 2009.
  24. ^ Lubanovic, Bill (2014). Introducing Python. Sebastopol, CA : O'Reilly Media. p. 305. ISBN 978-1-4493-5936-2. Retrieved 2023-07-31.
  25. ^ Cite error: The named reference tiobecurrent was invoked but never defined (see the help page).
  26. ^ Dean, Jeff; Monga, Rajat; et al. (9 November 2015). "TensorFlow: Large-scale machine learning on heterogeneous systems" (PDF). TensorFlow.org. Google Research. Archived (PDF) from the original on 20 November 2015. Retrieved 10 November 2015.
  27. ^ a b Kincaid, Jason (10 November 2009). "Google's Go: A New Programming Language That's Python Meets C++". TechCrunch. Archived from the original on 18 January 2010. Retrieved 29 January 2010.
  28. ^ The Cain Gang Ltd. "Python Metaclasses: Who? Why? When?" (PDF). Archived from the original (PDF) on 30 May 2009. Retrieved 27 June 2009.
  29. ^ "3.3. Special method names". The Python Language Reference. Python Software Foundation. Archived from the original on 15 December 2018. Retrieved 27 June 2009.
  30. ^ "PyDBC: method preconditions, method postconditions and class invariants for Python". Archived from the original on 23 November 2019. Retrieved 24 September 2011.
  31. ^ "Contracts for Python". Archived from the original on 15 June 2020. Retrieved 24 September 2011.
  32. ^ "PyDatalog". Archived from the original on 13 June 2020. Retrieved 22 July 2012.
  33. ^ "6.5 itertools – Functions creating iterators for efficient looping". Docs.python.org. Archived from the original on 14 June 2020. Retrieved 22 November 2016.
  34. ^ Peters, Tim (19 August 2004). "PEP 20 – The Zen of Python". Python Enhancement Proposals. Python Software Foundation. Archived from the original on 26 December 2018. Retrieved 24 November 2008.
  35. ^ Martelli, Alex; Ravenscroft, Anna; Ascher, David (2005). Python Cookbook, 2nd Edition. O'Reilly Media. p. 230. ISBN 978-0-596-00797-3. Archived from the original on 23 February 2020. Retrieved 14 November 2015.
  36. ^ "Python Culture". ebeab. January 21, 2014. Archived from the original on January 30, 2014.
  37. ^ Cannon, Brett. "Guido, Some Guys, and a Mailing List: How Python is Developed". python.org. Python Software Foundation. Archived from the original on 1 June 2009. Retrieved 27 June 2009.
  38. ^ Norwitz, Neal (8 April 2002). "[Python-Dev] Release Schedules (was Stability & change)". Archived from the original on 15 December 2018. Retrieved 27 June 2009.
  39. ^ "Python Buildbot". Python Developer's Guide. Python Software Foundation. Archived from the original on 5 June 2020. Retrieved 24 September 2011.
  40. ^ "Why is it called Python?". General Python FAQ. Docs.python.org. Archived from the original on 24 October 2012. Retrieved 3 January 2023.
  41. ^ "Whetting Your Appetite". The Python Tutorial. Python Software Foundation. Archived from the original on 26 October 2012. Retrieved 20 February 2012.
  42. ^ "In Python, should I use else after a return in an if block?". Stack Overflow. Stack Exchange. 17 February 2011. Archived from the original on 20 June 2019. Retrieved 6 May 2011.
  43. ^ "Quotes about Python". Python Software Foundation. Archived from the original on 3 June 2020. Retrieved 8 January 2012.
  44. ^ "Organizations Using Python". Python Software Foundation. Archived from the original on 21 August 2018. Retrieved 15 January 2009.
  45. ^ "Python : the holy grail of programming". CERN Bulletin (31/2006). CERN Publications. 31 July 2006. Archived from the original on 15 January 2013. Retrieved 11 February 2012.
  46. ^ Shafer, Daniel G. (17 January 2003). "Python Streamlines Space Shuttle Mission Design". Python Software Foundation. Archived from the original on 5 June 2020. Retrieved 24 November 2008.
  47. ^ Fortenberry, Tim (17 January 2003). "Industrial Light & Magic Runs on Python". Python Software Foundation. Archived from the original on 6 June 2020. Retrieved 11 February 2012.
  48. ^ Taft, Darryl K. (5 March 2007). "Python Slithers into Systems". eWeek.com. Ziff Davis Holdings. Archived from the original on 13 August 2021. Retrieved 24 September 2011.
  49. ^ "Usage statistics and market share of Python for websites". 2012. Archived from the original on 13 August 2021. Retrieved 18 December 2012.
  50. ^ "jasc psp9components". Archived from the original on 19 March 2008.
  51. ^ "About getting started with writing geoprocessing scripts". ArcGIS Desktop Help 9.2. Environmental Systems Research Institute. 17 November 2006. Archived from the original on 5 June 2020. Retrieved 11 February 2012.
  52. ^ CCP porkbelly (24 August 2010). "Stackless Python 2.7". EVE Community Dev Blogs. CCP Games. Archived from the original on 11 January 2014. Retrieved 11 January 2014. As you may know, EVE has at its core the programming language known as Stackless Python.
  53. ^ Caudill, Barry (20 September 2005). "Modding Sid Meier's Civilization IV". Sid Meier's Civilization IV Developer Blog. Firaxis Games. Archived from the original on 2 December 2010. 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.
  54. ^ "Python Language Guide (v1.0)". Google Documents List Data API v1.0. Archived from the original on 15 July 2010.
  55. ^ "Natural Language Toolkit – NLTK 3.5b1 documentation". www.nltk.org. Archived from the original on 13 June 2020. Retrieved 10 April 2020.
  56. ^ "Immunity: Knowing You're Secure". Archived from the original on 16 February 2009.
  57. ^ "Core Security". Core Security. Archived from the original on 9 June 2020. Retrieved 10 April 2020.
  58. ^ "What is Sugar?". Sugar Labs. Archived from the original on 9 January 2009. Retrieved 11 February 2012.
  59. ^ "PEP 380". Python.org. Archived from the original on 4 June 2020. Retrieved 3 December 2012.
  60. ^ "Why must 'self' be used explicitly in method definitions and calls?". Design and History FAQ. Python Software Foundation. Archived from the original on 24 October 2012. Retrieved 19 February 2012.
  61. ^ "The Python Language Reference, section 3.3. New-style and classic classes, for release 2.7.1". Archived from the original on 26 October 2012. Retrieved 12 January 2011.
  62. ^ Zadka, Moshe; van Rossum, Guido (11 March 2001). "PEP 237 – Unifying Long Integers and Integers". Python Enhancement Proposals. Python Software Foundation. Archived from the original on 28 May 2020. Retrieved 24 September 2011.
  63. ^ "Why Python's Integer Division Floors". 24 August 2010. Archived from the original on 5 June 2020. Retrieved 25 August 2010.
  64. ^ "round", The Python standard library, release 2.7, §2: Built-in functions, archived from the original on 27 October 2012, retrieved 14 August 2011
  65. ^ "round", The Python standard library, release 3.2, §2: Built-in functions, archived from the original on 25 October 2012, retrieved 14 August 2011
  66. ^ Beazley, David M. (2009). Python Essential Reference (4th ed.). Addison-Wesley Professional. p. 66. ISBN 9780672329784.
  67. ^ Kernighan, Brian W.; Ritchie, Dennis M. (1988). The C Programming Language (2nd ed.). p. 206.
  68. ^ van Rossum, Guido (5 June 2001). "PEP 7 – Style Guide for C Code". Python Enhancement Proposals. Python Software Foundation. Archived from the original on 1 June 2020. Retrieved 24 November 2008.
  69. ^ "CPython byte code". Docs.python.org. Archived from the original on 5 June 2020. Retrieved 16 February 2016.
  70. ^ "Python 2.5 internals" (PDF). Archived (PDF) from the original on 6 August 2012. Retrieved 19 April 2011.
  71. ^ "An Interview with Guido van Rossum". Oreilly.com. Archived from the original on 16 July 2014. Retrieved 24 November 2008.
  72. ^ "PyPy compatibility". Pypy.org. Archived from the original on 6 June 2020. Retrieved 3 December 2012.
  73. ^ "speed comparison between CPython and Pypy". Speed.pypy.org. Archived from the original on 10 May 2021. Retrieved 3 December 2012.
  74. ^ "Application-level Stackless features – PyPy 2.0.2 documentation". Doc.pypy.org. Archived from the original on 4 June 2020. Retrieved 17 July 2013.
  75. ^ "Plans for optimizing Python". Google Project Hosting. 15 December 2009. Archived from the original on 11 April 2016. Retrieved 24 September 2011.
  76. ^ Piotrowski, Przemyslaw (July 2006). "Build a Rapid Web Development Environment for Python Server Pages and Oracle". Oracle Technology Network. Oracle. Archived from the original on 2 April 2019. Retrieved 12 March 2012.
  77. ^ Eby, Phillip J. (7 December 2003). "PEP 333 – Python Web Server Gateway Interface v1.0". Python Enhancement Proposals. Python Software Foundation. Archived from the original on 14 June 2020. Retrieved 19 February 2012.
  78. ^ "Gotchas for Python Users". boo.codehaus.org. Codehaus Foundation. Archived from the original on 11 December 2008. Retrieved 24 November 2008.
  79. ^ Esterbrook, Charles. "Acknowledgements". cobra-language.com. Cobra Language. Archived from the original on 8 February 2008. Retrieved 7 April 2010.
  80. ^ "Proposals: iterators and generators [ES4 Wiki]". wiki.ecmascript.org. Archived from the original on 20 October 2007. Retrieved 24 November 2008.
  81. ^ Strachan, James (29 August 2003). "Groovy – the birth of a new dynamic language for the Java platform". Archived from the original on 5 April 2007. Retrieved 11 June 2007.
  82. ^ "An Interview with the Creator of Ruby". Linuxdevcenter.com. Archived from the original on 28 April 2018. Retrieved 3 December 2012.
  83. ^ Kupries, Andreas; Fellows, Donal K. (14 September 2000). "TIP #3: TIP Format". tcl.tk. Tcl Developer Xchange. Archived from the original on 13 July 2017. Retrieved 24 November 2008.
  84. ^ Gustafsson, Per; Niskanen, Raimo (29 January 2007). "EEP 1: EEP Purpose and Guidelines". erlang.org. Archived from the original on 15 June 2020. Retrieved 19 April 2011.
  85. ^ Fairchild, Carlie (12 July 2018). "Guido van Rossum Stepping Down from Role as Python's Benevolent Dictator For Life". Linux Journal. Archived from the original on 13 July 2018. Retrieved 13 July 2018.