Text of wiki.python.org › python › guides › HowToEditPythonCode.html as Styx crawled it on Nov 18, 2026. The page may have changed since. Only its words are kept, without pictures or layout, and only the first part of a long page.

Open the live page

How to Edit Python Code - Python Wiki

Python Wiki Python Wiki / Python Wiki / Guides and How-Tos / How to Edit Python Code View as Markdown How to Edit Python Code ¶ Legacy Wiki Page This page was migrated from the old MoinMoin-based wiki. Information may be outdated or no longer applicable. For current documentation, see python.org . History ¶ Python was conceived in the late 1980s and its implementation was started in December 1989 by Guido van Rossum at CWI in Amsterdam.

Python is a successor to the ABC programming language (itself inspired by SETL) capable of exception handling and interfacing with the Amoeba operating system. Van Rossum is Python’s principal author, and was for many years known by the humorous title Benevolent Dictator for Life (BDFL). Python evolution is now guided by an elected Steering Committee. Programming philosophy ¶ Python is a multi-paradigm programming language.

Rather than forcing programmers to adopt a particular style of programming, it permits several styles: object-oriented programming and structured programming are fully supported, and there are a number of language features which support functional programming and aspect-oriented programming (including metaprogramming and “by magic” methods). Many other paradigms are supported using extensions, such as pyDBC and Contracts for Python which allow Design by Contract.

Rather than requiring all desired functionality to be built into the language’s core, Python was designed to be highly extensible. New built-in modules can be easily written in C, C++ or Cython. Python can also be used as an extension language for existing modules and applications that need a programmable interface. This design, a small core language with a large standard library with an easily extensible interpreter, was intended by Van Rossum from the very start because of his frustrations with ABC (which espoused the opposite mindset).

Name and neologisms ¶ An important goal of the Python developers is making Python fun to use. This is reflected in the origin of the name (based on the television series Monty Python’s Flying Circus), in the common practice of using Monty Python references in example code, and in an occasionally playful approach to tutorials and reference materials.[24][25] For example, the metasyntactic variables often used in Python literature are spam and eggs, instead of the traditional foo and bar.

Usage ¶ Python is often used as a scripting language for web applications, e.g. via mod_wsgi for the Apache web server. With Web Server Gateway Interface, a standard API has been developed to facilitate these applications. Web application frameworks like Django, Pylons, TurboGears , web2py, Flask, and Zope support developers in the design and maintenance of complex applications. Libraries like NumPy , SciPy , and Matplotlib allow Python to be used effectively in scientific computing.

Syntax and semantics ¶ Python was intended to be a highly readable language. It is designed to have an uncluttered visual layout, frequently using English keywords where other languages use punctuation. Python requires less boilerplate than traditional manifestly typed structured languages such as C or Pascal, and has a smaller number of syntactic exceptions and special cases than either of these. For a detailed description of the differences between 2.x and 3.x versions, see History of Python.

Indentation ¶ Python uses whitespace indentation, rather than curly braces or keywords, to delimit blocks (a feature also known as the off-side rule ). An increase in indentation comes after certain statements; a decrease in indentation signifies the end of the current block. Statements and control flow ¶ Python’s statements include (among others): The if statement, which conditionally executes a block of code, along with else and elif (a contraction of else-if).

The for statement, which iterates over an iterable object, capturing each element to a 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 by except clauses; it also ensures that clean-up code in a finally block will always be run regardless of how the block exits.

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 (from Python 2.5), which encloses a code block within a context manager (for example, acquiring a lock before the block of code is run, and releasing the lock afterward). The pass statement, which serves as a NOP and can be used in place of a code block.

The assert statement, used during debugging to check for conditions that ought to apply. The yield statement, which returns a value from a generator function. (From Python 2.5, yield is also an operator. This form is used to implement coroutines – see below.) Expressions ¶ In Python 3, the result of the division operator / with integer operands is always a floating-point value; the operator // may be used to perform integer division (the result truncated to an integer).

In Python 2, the / operator on integers performs integer division. Floating-point division on integers can be achieved by converting one of the integers to a float (e.g. float(x) / y ), or, since 2.2, the behavior of Python 3 can be enabled using from __future__ import division . In Python, == compares by value, in contrast to Java, where it compares by reference. (Value comparisons in Java use the equals() method.) Python’s is operator may be used to compare object identities (comparison by reference).

Comparisons may be chained, for example a <= b <= c . Python uses the words and , or , not for its boolean operators rather than the symbolic && , || , ! used in C. Python has a type of expression known as a list comprehension. Python 2.4 extended list comprehensions into a more general expression known as a generator expression. Anonymous functions are implemented using lambda expressions; however, these are limited in that the body can only be a single expression.

Conditional expressions in Python are written as x if c else y (different in order of operands from the ?: operator common to many other languages). Python makes a distinction between lists and tuples. Lists, written as [1, 2, 3] , are mutable, and cannot be used as the keys of dictionaries (dictionary keys must be immutable in Python). Tuples, written as (1, 2, 3) , are immutable and thus can be used as the keys of dictionaries, provided all elements of the tuple are immutable.

The parentheses around the tuple are optional in some contexts. Tuples can appear on the left side of an equal sign; hence a statement like x, y = y, x can be used to swap two variables. Multiple string-formatting operations are supported. The original % operator provided behavior analogous to printf format strings in C, e.g. foo=%s bar=%d" % ("blah", 2) evaluates to foo=blah bar=2 . String templates were introduced in Python 2.4.

Python 3.0 brought in the string format() method, with syntax like foo={0} bar={1}".format("blah", 2) . Formatted string literals (“F-strings”) were introduced in 3.6, with syntax like f'foo={"blah"} bar={2}' ” Python has various kinds of string literals: Strings are delimited by single or double quotation marks. Unlike in Unix shells, Perl and Perl-influenced languages, single quotation marks and double quotation marks function identically.

Both kinds of strings use the backslash ( \ ) as an escape character and there is no implicit string interpolation such as “$foo”. Triple-quoted strings, which begin and end with a series of three single or double quotation marks, may span multiple lines and function like here-documents in shells, Perl and Ruby. Methods ¶ Methods on objects are functions attached to the object’s class; the synt

The rest of this page is on the live site.