The default Python prompt of the interactive shell. Often seen for code
examples which can be executed interactively in the interpreter.
The default Python prompt of the interactive shell when entering code for
an indented code block or within a pair of matching left and right
A value associated with an object which is referenced by name using
dotted expressions. For example, if an object *o* has an attribute
*a* it would be referenced as *o.a*.
Benevolent Dictator For Life, a.k.a. `Guido van Rossum
<http://www.python.org/~guido/>`_, Python's creator.
Python source code is compiled into bytecode, the internal representation
of a Python program in the interpreter. The bytecode is also cached in
A template for creating user-defined objects. Class definitions
normally contain method definitions which operate on instances of the
Any class which does not inherit from :class:`object`. See
:term:`new-style class`. Classic classes will be removed in Python 3.0.
The implicit conversion of an instance of one type to another during an
operation which involves two arguments of the same type. For example,
``operator.add(3.0, 4.5)``. Without coercion, all arguments of even
compatible types would have to be normalized to the same value by the
programmer, e.g., ``float(3)+4.5`` rather than just ``3+4.5``.
An extension of the familiar real number system in which all numbers are
expressed as a sum of a real part and an imaginary part. Imaginary
:mod:`math` module, use :mod:`cmath`. Use of complex numbers is a fairly
advanced mathematical feature. If you're not aware of a need for them,
it's almost certain you can safely ignore them.
An object which controls the environment seen in a :keyword:`with`
statement by defining :meth:`__enter__` and :meth:`__exit__` methods.
class methods, static methods, and reference to super classes.
For more information about descriptors' methods, see :ref:`descriptors`.
An associative array, where arbitrary keys are mapped to values. The use
of :class:`dict` closely resembles that for :class:`list`, but the keys can
of the enclosing class, function or module. Since it is available via
introspection, it is the canonical place for documentation of the
A pythonic programming style which determines an object's type by inspection
of its method or attribute signature rather than by explicit relationship
to some type object ("If it looks like a duck and quacks like a duck, it
:func:`isinstance`. (Note, however, that duck-typing can be complemented
with abstract base classes.) Instead, it typically employs :func:`hasattr`
tests or :term:`EAFP` programming.
Easier to ask for forgiveness than permission. This common Python coding
style assumes the existence of valid keys or attributes and catches
exceptions if the assumption proves false. This clean and fast style is
characterized by the presence of many :keyword:`try` and :keyword:`except`
- statements. The technique contrasts with the :term:`LBYL` style
+ statements. The technique contrasts with the :term:`LBYL` style
common to many other languages such as C.
which are not compatible with the current interpreter. For example, the
expression ``11/4`` currently evaluates to ``2``. If the module in which
it is executed had enabled *true division* by executing::
from __future__ import division
the expression ``11/4`` would evaluate to ``2.75``. By importing the
:mod:`__future__` module and evaluating its variables, you can see when a
new feature was first added to the language and when it will become the
_Feature((2, 2, 0, 'alpha', 2), (3, 0, 0, 'alpha', 0), 8192)
The process of freeing memory when it is not used anymore. Python
performs garbage collection via reference counting and a cyclic garbage
collector that is able to detect and break reference cycles.
A function which returns an iterator. It looks like a normal function
except that values are returned to the caller using a :keyword:`yield`
stopped at the :keyword:`yield` keyword (returning the result) and is
resumed there when the next element is requested by calling the
:meth:`next` method of the returned iterator.
.. index:: single: generator expression
An expression that returns a generator. It looks like a normal expression
followed by a :keyword:`for` expression defining a loop variable, range,
and an optional :keyword:`if` expression. The combined expression
generates values for an enclosing function::
>>> sum(i*i for i in range(10)) # sum of squares 0, 1, 4, ... 81
See :term:`global interpreter lock`.
The lock used by Python threads to assure that only one thread
executes in the :term:`CPython` :term:`virtual machine` at a time.
containers (such as lists or dictionaries) are. Objects which are
instances of user-defined classes are hashable by default; they all
compare unequal, and their hash value is their :func:`id`.
An Integrated Development Environment for Python. IDLE is a basic editor
and interpreter environment which ships with the standard distribution of
Python. Good for beginners, it also serves as clear example code for
those wanting to implement a moderately sophisticated, multi-platform GUI
An object with a fixed value. Immutable objects include numbers, strings and
tuples. Such an object cannot be altered. A new object has to
be created if a different value has to be stored. They play an important
role in places where a constant hash value is needed, for example as a key
Mathematical division discarding any remainder. For example, the
expression ``11/4`` currently evaluates to ``2`` in contrast to the
divided by a float will result in a float value, possibly with a decimal
fraction. Integer division can be forced by using the ``//`` operator
instead of the ``/`` operator. See also :term:`__future__`.
Python has an interactive interpreter which means you can enter
statements and expressions at the interpreter prompt, immediately
arguments (possibly by selecting it from your computer's main
menu). It is a very powerful way to test out new ideas or inspect
modules and packages (remember ``help(x)``).
Python is an interpreted language, as opposed to a compiled one,
though the distinction can be blurry because of the presence of the
Interpreted languages typically have a shorter development/debug cycle
than compiled ones, though their programs generally also run more
slowly. See also :term:`interactive`.
A container object capable of returning its members one at a
time. Examples of iterables include all sequence types (such as
statement does that automatically for you, creating a temporary unnamed
variable to hold the iterator for the duration of the loop. See also
:term:`iterator`, :term:`sequence`, and :term:`generator`.
An object representing a stream of data. Repeated calls to the iterator's
:meth:`next` method return successive items in the stream. When no more
:func:`iter` function or use it in a :keyword:`for` loop. Attempting this
with an iterator will just return the same exhausted iterator object used
in the previous iteration pass, making it appear like an empty container.
More information can be found in :ref:`typeiter`.
A built-in Python :term:`sequence`. Despite its name it is more akin
to an array in other languages than to a linked list since access to
A compact way to process all or part of the elements in a sequence and
return a list with the results. ``result = ["0x%02x" % x for x in
even hex numbers (0x..) in the range from 0 to 255. The :keyword:`if`
clause is optional. If omitted, all elements in ``range(256)`` are
A container object (such as :class:`dict`) which supports arbitrary key
lookups using the special method :meth:`__getitem__`.
The class of a class. Class definitions create a class name, a class
dictionary, and a list of base classes. The metaclass is responsible for
of an instance of that class, the method will get the instance object as
its first :term:`argument` (which is usually called ``self``).
See :term:`function` and :term:`nested scope`.
Mutable objects can change their value but keep their :func:`id`. See
:func:`collections.namedtuple`. The latter approach automatically
provides extra features such as a self-documenting representation like
The place where a variable is stored. Namespaces are implemented as
dictionaries. There are the local, global and builtin namespaces as well
:func:`random.seed` or :func:`itertools.izip` makes it clear that those
functions are implemented by the :mod:`random` and :mod:`itertools`
The ability to refer to a variable in an enclosing definition. For
instance, a function defined inside another function can refer to
reference and not for assignment which will always write to the innermost
scope. In contrast, local variables both read and write in the innermost
scope. Likewise, global variables read and write to the global namespace.
Any class which inherits from :class:`object`. This includes all built-in
types like :class:`list` and :class:`dict`. Only new-style classes can
Any data with state (attributes or value) and defined behavior
(methods). Also the ultimate base class of any :term:`new-style
The arguments assigned to local names inside a function or method,
determined by the order in which they were given in the call. ``*`` is
definition), or pass several arguments as a list to a function. See
Nickname for the next major Python version, 3.0 (coined long ago
when the release of version 3 was something in the distant future.) This
is also abbreviated "Py3k".
to loop over all elements of an iterable using a :keyword:`for`
statement. Many other languages don't have this type of construct, so
people unfamiliar with Python sometimes use a numerical counter instead::
for i in range(len(food)):
dictionaries. Though popular, the technique is somewhat tricky to get
right and is best reserved for rare cases where there are large numbers of
instances in a memory-critical application.
An :term:`iterable` which supports efficient element access using integer
indices via the :meth:`__getitem__` special method and defines a
A computer defined entirely in software. Python's virtual machine
executes the :term:`bytecode` emitted by the bytecode compiler.
Listing of Python design principles and philosophies that are helpful in
understanding and using the language. The listing can be found by typing