blob: 19b02f4e8f8e38beb63a4a4aedd9a324af06fbcc [file] [log] [blame]
Georg Brandl437e6a32007-08-17 06:27:11 +00001.. _glossary:
2
3********
4Glossary
5********
6
7.. if you add new entries, keep the alphabetical sorting!
8
9.. glossary::
10
11 ``>>>``
Skip Montanarof02c5f32008-09-15 02:03:05 +000012 The default Python prompt of the interactive shell. Often seen for code
13 examples which can be executed interactively in the interpreter.
Georg Brandlc62ef8b2009-01-03 20:55:06 +000014
Georg Brandl437e6a32007-08-17 06:27:11 +000015 ``...``
Skip Montanarof02c5f32008-09-15 02:03:05 +000016 The default Python prompt of the interactive shell when entering code for
17 an indented code block or within a pair of matching left and right
18 delimiters (parentheses, square brackets or curly braces).
Georg Brandl584265b2007-12-02 14:58:50 +000019
Georg Brandl5a42ca62008-05-20 07:20:12 +000020 2to3
21 A tool that tries to convert Python 2.x code to Python 3.x code by
Georg Brandl09302282010-10-06 09:32:48 +000022 handling most of the incompatibilities which can be detected by parsing the
Georg Brandl5a42ca62008-05-20 07:20:12 +000023 source and traversing the parse tree.
24
25 2to3 is available in the standard library as :mod:`lib2to3`; a standalone
Benjamin Peterson40202212008-07-24 02:45:37 +000026 entry point is provided as :file:`Tools/scripts/2to3`. See
27 :ref:`2to3-reference`.
Georg Brandl5a42ca62008-05-20 07:20:12 +000028
Benjamin Peterson9385b9d2008-07-03 12:57:35 +000029 abstract base class
Éric Araujo8fde9502011-07-29 11:34:17 +020030 Abstract base classes complement :term:`duck-typing` by
Georg Brandld7d4fd72009-07-26 14:37:28 +000031 providing a way to define interfaces when other techniques like
Éric Araujo8fde9502011-07-29 11:34:17 +020032 :func:`hasattr` would be clumsy or subtly wrong (for example with
Éric Araujoe0054c52011-08-19 09:15:47 +020033 :ref:`magic methods <new-style-special-lookup>`). ABCs introduce virtual
34 subclasses, which are classes that don't inherit from a class but are
35 still recognized by :func:`isinstance` and :func:`issubclass`; see the
36 :mod:`abc` module documentation. Python comes with many built-in ABCs for
Georg Brandld7d4fd72009-07-26 14:37:28 +000037 data structures (in the :mod:`collections` module), numbers (in the
38 :mod:`numbers` module), and streams (in the :mod:`io` module). You can
Éric Araujo8fde9502011-07-29 11:34:17 +020039 create your own ABCs with the :mod:`abc` module.
Benjamin Petersonaac51b82008-07-01 23:33:06 +000040
Georg Brandl584265b2007-12-02 14:58:50 +000041 argument
Chris Jerdonek8da82682012-11-29 19:03:37 -080042 A value passed to a :term:`function` (or :term:`method`) when calling the
43 function. There are two types of arguments:
Georg Brandl584265b2007-12-02 14:58:50 +000044
Chris Jerdonek8da82682012-11-29 19:03:37 -080045 * :dfn:`keyword argument`: an argument preceded by an identifier (e.g.
46 ``name=``) in a function call or passed as a value in a dictionary
47 preceded by ``**``. For example, ``3`` and ``5`` are both keyword
48 arguments in the following calls to :func:`complex`::
49
50 complex(real=3, imag=5)
51 complex(**{'real': 3, 'imag': 5})
52
53 * :dfn:`positional argument`: an argument that is not a keyword argument.
54 Positional arguments can appear at the beginning of an argument list
55 and/or be passed as elements of an :term:`iterable` preceded by ``*``.
56 For example, ``3`` and ``5`` are both positional arguments in the
57 following calls::
58
59 complex(3, 5)
60 complex(*(3, 5))
61
62 Arguments are assigned to the named local variables in a function body.
63 See the :ref:`calls` section for the rules governing this assignment.
64 Syntactically, any expression can be used to represent an argument; the
65 evaluated value is assigned to the local variable.
66
67 See also the :term:`parameter` glossary entry and the FAQ question on
68 :ref:`the difference between arguments and parameters
69 <faq-argument-vs-parameter>`.
Skip Montanaro9feab312008-09-15 02:19:53 +000070
71 attribute
72 A value associated with an object which is referenced by name using
73 dotted expressions. For example, if an object *o* has an attribute
74 *a* it would be referenced as *o.a*.
Georg Brandlc62ef8b2009-01-03 20:55:06 +000075
Georg Brandl437e6a32007-08-17 06:27:11 +000076 BDFL
77 Benevolent Dictator For Life, a.k.a. `Guido van Rossum
78 <http://www.python.org/~guido/>`_, Python's creator.
Georg Brandlc62ef8b2009-01-03 20:55:06 +000079
Ezio Melotti1c0d8a72013-04-30 23:33:31 +030080 bytes-like object
81 An object that supports the :ref:`bufferobjects`, like :class:`bytes` or
82 :class:`bytearray`.
83
Georg Brandl63fa1682007-10-21 10:24:20 +000084 bytecode
85 Python source code is compiled into bytecode, the internal representation
Éric Araujoa8f66dd2011-08-19 01:27:00 +020086 of a Python program in the CPython interpreter. The bytecode is also
87 cached in ``.pyc`` and ``.pyo`` files so that executing the same file is
88 faster the second time (recompilation from source to bytecode can be
89 avoided). This "intermediate language" is said to run on a
90 :term:`virtual machine` that executes the machine code corresponding to
91 each bytecode. Do note that bytecodes are not expected to work between
92 different Python virtual machines, nor to be stable between Python
93 releases.
Skip Montanaro9feab312008-09-15 02:19:53 +000094
Georg Brandl2b4eda42010-07-03 10:25:54 +000095 A list of bytecode instructions can be found in the documentation for
96 :ref:`the dis module <bytecodes>`.
97
Skip Montanaro9feab312008-09-15 02:19:53 +000098 class
99 A template for creating user-defined objects. Class definitions
100 normally contain method definitions which operate on instances of the
101 class.
Georg Brandlc62ef8b2009-01-03 20:55:06 +0000102
Georg Brandl437e6a32007-08-17 06:27:11 +0000103 classic class
104 Any class which does not inherit from :class:`object`. See
Ezio Melotti510ff542012-05-03 19:21:40 +0300105 :term:`new-style class`. Classic classes have been removed in Python 3.
Georg Brandlc62ef8b2009-01-03 20:55:06 +0000106
Georg Brandl437e6a32007-08-17 06:27:11 +0000107 coercion
108 The implicit conversion of an instance of one type to another during an
109 operation which involves two arguments of the same type. For example,
110 ``int(3.15)`` converts the floating point number to the integer ``3``, but
111 in ``3+4.5``, each argument is of a different type (one int, one float),
112 and both must be converted to the same type before they can be added or it
113 will raise a ``TypeError``. Coercion between two operands can be
Georg Brandld7d4fd72009-07-26 14:37:28 +0000114 performed with the ``coerce`` built-in function; thus, ``3+4.5`` is
Georg Brandl437e6a32007-08-17 06:27:11 +0000115 equivalent to calling ``operator.add(*coerce(3, 4.5))`` and results in
116 ``operator.add(3.0, 4.5)``. Without coercion, all arguments of even
117 compatible types would have to be normalized to the same value by the
118 programmer, e.g., ``float(3)+4.5`` rather than just ``3+4.5``.
Georg Brandlc62ef8b2009-01-03 20:55:06 +0000119
Georg Brandl437e6a32007-08-17 06:27:11 +0000120 complex number
121 An extension of the familiar real number system in which all numbers are
122 expressed as a sum of a real part and an imaginary part. Imaginary
123 numbers are real multiples of the imaginary unit (the square root of
124 ``-1``), often written ``i`` in mathematics or ``j`` in
Georg Brandld7d4fd72009-07-26 14:37:28 +0000125 engineering. Python has built-in support for complex numbers, which are
Georg Brandl437e6a32007-08-17 06:27:11 +0000126 written with this latter notation; the imaginary part is written with a
127 ``j`` suffix, e.g., ``3+1j``. To get access to complex equivalents of the
128 :mod:`math` module, use :mod:`cmath`. Use of complex numbers is a fairly
129 advanced mathematical feature. If you're not aware of a need for them,
130 it's almost certain you can safely ignore them.
Georg Brandlc62ef8b2009-01-03 20:55:06 +0000131
Skip Montanaroffe455c2007-12-08 15:23:31 +0000132 context manager
Skip Montanarof02c5f32008-09-15 02:03:05 +0000133 An object which controls the environment seen in a :keyword:`with`
Skip Montanaroffe455c2007-12-08 15:23:31 +0000134 statement by defining :meth:`__enter__` and :meth:`__exit__` methods.
135 See :pep:`343`.
136
Skip Montanarof02c5f32008-09-15 02:03:05 +0000137 CPython
Antoine Pitrou9f41bb32011-01-06 16:35:14 +0000138 The canonical implementation of the Python programming language, as
139 distributed on `python.org <http://python.org>`_. The term "CPython"
140 is used when necessary to distinguish this implementation from others
141 such as Jython or IronPython.
Skip Montanarof02c5f32008-09-15 02:03:05 +0000142
Georg Brandl584265b2007-12-02 14:58:50 +0000143 decorator
144 A function returning another function, usually applied as a function
145 transformation using the ``@wrapper`` syntax. Common examples for
146 decorators are :func:`classmethod` and :func:`staticmethod`.
147
148 The decorator syntax is merely syntactic sugar, the following two
149 function definitions are semantically equivalent::
150
151 def f(...):
152 ...
153 f = staticmethod(f)
154
155 @staticmethod
156 def f(...):
157 ...
158
Éric Araujoa8f66dd2011-08-19 01:27:00 +0200159 The same concept exists for classes, but is less commonly used there. See
160 the documentation for :ref:`function definitions <function>` and
161 :ref:`class definitions <class>` for more about decorators.
Georg Brandl5066c0c2008-12-05 18:00:06 +0000162
Georg Brandl437e6a32007-08-17 06:27:11 +0000163 descriptor
Skip Montanarof02c5f32008-09-15 02:03:05 +0000164 Any *new-style* object which defines the methods :meth:`__get__`,
Georg Brandl5e52db02007-10-21 10:45:46 +0000165 :meth:`__set__`, or :meth:`__delete__`. When a class attribute is a
Georg Brandl437e6a32007-08-17 06:27:11 +0000166 descriptor, its special binding behavior is triggered upon attribute
Georg Brandl5e52db02007-10-21 10:45:46 +0000167 lookup. Normally, using *a.b* to get, set or delete an attribute looks up
168 the object named *b* in the class dictionary for *a*, but if *b* is a
169 descriptor, the respective descriptor method gets called. Understanding
170 descriptors is a key to a deep understanding of Python because they are
171 the basis for many features including functions, methods, properties,
172 class methods, static methods, and reference to super classes.
173
174 For more information about descriptors' methods, see :ref:`descriptors`.
Georg Brandlc62ef8b2009-01-03 20:55:06 +0000175
Georg Brandl437e6a32007-08-17 06:27:11 +0000176 dictionary
Senthil Kumaranc768d4c2012-03-12 10:05:04 -0700177 An associative array, where arbitrary keys are mapped to values. The
178 keys can be any object with :meth:`__hash__` and :meth:`__eq__` methods.
179 Called a hash in Perl.
Georg Brandle64f7382008-07-20 11:50:29 +0000180
181 docstring
Skip Montanarof02c5f32008-09-15 02:03:05 +0000182 A string literal which appears as the first expression in a class,
183 function or module. While ignored when the suite is executed, it is
184 recognized by the compiler and put into the :attr:`__doc__` attribute
185 of the enclosing class, function or module. Since it is available via
186 introspection, it is the canonical place for documentation of the
Georg Brandle64f7382008-07-20 11:50:29 +0000187 object.
Georg Brandlc62ef8b2009-01-03 20:55:06 +0000188
189 duck-typing
Georg Brandle85e1ae2010-10-06 09:17:24 +0000190 A programming style which does not look at an object's type to determine
191 if it has the right interface; instead, the method or attribute is simply
192 called or used ("If it looks like a duck and quacks like a duck, it
Georg Brandl437e6a32007-08-17 06:27:11 +0000193 must be a duck.") By emphasizing interfaces rather than specific types,
194 well-designed code improves its flexibility by allowing polymorphic
195 substitution. Duck-typing avoids tests using :func:`type` or
Georg Brandl04eba2c2010-07-11 08:56:18 +0000196 :func:`isinstance`. (Note, however, that duck-typing can be complemented
Éric Araujoa8f66dd2011-08-19 01:27:00 +0200197 with :term:`abstract base classes <abstract base class>`.) Instead, it
198 typically employs :func:`hasattr` tests or :term:`EAFP` programming.
Georg Brandlc62ef8b2009-01-03 20:55:06 +0000199
Georg Brandl437e6a32007-08-17 06:27:11 +0000200 EAFP
201 Easier to ask for forgiveness than permission. This common Python coding
202 style assumes the existence of valid keys or attributes and catches
203 exceptions if the assumption proves false. This clean and fast style is
204 characterized by the presence of many :keyword:`try` and :keyword:`except`
Georg Brandlc62ef8b2009-01-03 20:55:06 +0000205 statements. The technique contrasts with the :term:`LBYL` style
Skip Montanarof02c5f32008-09-15 02:03:05 +0000206 common to many other languages such as C.
Georg Brandl437e6a32007-08-17 06:27:11 +0000207
Georg Brandl584265b2007-12-02 14:58:50 +0000208 expression
209 A piece of syntax which can be evaluated to some value. In other words,
Éric Araujoa8f66dd2011-08-19 01:27:00 +0200210 an expression is an accumulation of expression elements like literals,
211 names, attribute access, operators or function calls which all return a
212 value. In contrast to many other languages, not all language constructs
213 are expressions. There are also :term:`statement`\s which cannot be used
214 as expressions, such as :keyword:`print` or :keyword:`if`. Assignments
215 are also statements, not expressions.
Georg Brandl584265b2007-12-02 14:58:50 +0000216
Georg Brandl437e6a32007-08-17 06:27:11 +0000217 extension module
Georg Brandl28dadd92011-02-25 10:50:32 +0000218 A module written in C or C++, using Python's C API to interact with the
219 core and with user code.
Georg Brandl584265b2007-12-02 14:58:50 +0000220
Éric Araujoa8f66dd2011-08-19 01:27:00 +0200221 file object
222 An object exposing a file-oriented API (with methods such as
223 :meth:`read()` or :meth:`write()`) to an underlying resource. Depending
224 on the way it was created, a file object can mediate access to a real
Sandro Tosifd4c4b12012-06-02 23:40:59 +0200225 on-disk file or to another type of storage or communication device
Éric Araujoa8f66dd2011-08-19 01:27:00 +0200226 (for example standard input/output, in-memory buffers, sockets, pipes,
227 etc.). File objects are also called :dfn:`file-like objects` or
228 :dfn:`streams`.
229
230 There are actually three categories of file objects: raw binary files,
231 buffered binary files and text files. Their interfaces are defined in the
232 :mod:`io` module. The canonical way to create a file object is by using
233 the :func:`open` function.
234
235 file-like object
236 A synonym for :term:`file object`.
237
Georg Brandl624f3372009-03-31 16:11:45 +0000238 finder
239 An object that tries to find the :term:`loader` for a module. It must
240 implement a method named :meth:`find_module`. See :pep:`302` for
241 details.
242
Raymond Hettingerf1b678d2010-09-01 22:25:41 +0000243 floor division
244 Mathematical division that rounds down to nearest integer. The floor
245 division operator is ``//``. For example, the expression ``11 // 4``
246 evaluates to ``2`` in contrast to the ``2.75`` returned by float true
247 division. Note that ``(-11) // 4`` is ``-3`` because that is ``-2.75``
248 rounded *downward*. See :pep:`238`.
249
Georg Brandl584265b2007-12-02 14:58:50 +0000250 function
251 A series of statements which returns some value to a caller. It can also
Chris Jerdonekcf4710c2012-12-25 14:50:21 -0800252 be passed zero or more :term:`arguments <argument>` which may be used in
253 the execution of the body. See also :term:`parameter`, :term:`method`,
254 and the :ref:`function` section.
Georg Brandl584265b2007-12-02 14:58:50 +0000255
Georg Brandl437e6a32007-08-17 06:27:11 +0000256 __future__
Raymond Hettingerf1b678d2010-09-01 22:25:41 +0000257 A pseudo-module which programmers can use to enable new language features
Georg Brandl437e6a32007-08-17 06:27:11 +0000258 which are not compatible with the current interpreter. For example, the
259 expression ``11/4`` currently evaluates to ``2``. If the module in which
260 it is executed had enabled *true division* by executing::
Georg Brandlc62ef8b2009-01-03 20:55:06 +0000261
Georg Brandl437e6a32007-08-17 06:27:11 +0000262 from __future__ import division
Georg Brandlc62ef8b2009-01-03 20:55:06 +0000263
Georg Brandl437e6a32007-08-17 06:27:11 +0000264 the expression ``11/4`` would evaluate to ``2.75``. By importing the
265 :mod:`__future__` module and evaluating its variables, you can see when a
266 new feature was first added to the language and when it will become the
267 default::
Georg Brandlc62ef8b2009-01-03 20:55:06 +0000268
Georg Brandl437e6a32007-08-17 06:27:11 +0000269 >>> import __future__
270 >>> __future__.division
271 _Feature((2, 2, 0, 'alpha', 2), (3, 0, 0, 'alpha', 0), 8192)
272
273 garbage collection
274 The process of freeing memory when it is not used anymore. Python
275 performs garbage collection via reference counting and a cyclic garbage
276 collector that is able to detect and break reference cycles.
Georg Brandlc62ef8b2009-01-03 20:55:06 +0000277
Georg Brandlea2d3892010-04-02 09:11:49 +0000278 .. index:: single: generator
279
Georg Brandl437e6a32007-08-17 06:27:11 +0000280 generator
Skip Montanarof02c5f32008-09-15 02:03:05 +0000281 A function which returns an iterator. It looks like a normal function
Raymond Hettingerf1b678d2010-09-01 22:25:41 +0000282 except that it contains :keyword:`yield` statements for producing a series
283 a values usable in a for-loop or that can be retrieved one at a time with
284 the :func:`next` function. Each :keyword:`yield` temporarily suspends
285 processing, remembering the location execution state (including local
286 variables and pending try-statements). When the generator resumes, it
287 picks-up where it left-off (in contrast to functions which start fresh on
288 every invocation).
Georg Brandlc62ef8b2009-01-03 20:55:06 +0000289
Georg Brandl437e6a32007-08-17 06:27:11 +0000290 .. index:: single: generator expression
Georg Brandlc62ef8b2009-01-03 20:55:06 +0000291
Georg Brandl437e6a32007-08-17 06:27:11 +0000292 generator expression
Georg Brandlea2d3892010-04-02 09:11:49 +0000293 An expression that returns an iterator. It looks like a normal expression
Georg Brandl437e6a32007-08-17 06:27:11 +0000294 followed by a :keyword:`for` expression defining a loop variable, range,
295 and an optional :keyword:`if` expression. The combined expression
296 generates values for an enclosing function::
Georg Brandlc62ef8b2009-01-03 20:55:06 +0000297
Georg Brandl437e6a32007-08-17 06:27:11 +0000298 >>> sum(i*i for i in range(10)) # sum of squares 0, 1, 4, ... 81
299 285
Georg Brandlc62ef8b2009-01-03 20:55:06 +0000300
Georg Brandl437e6a32007-08-17 06:27:11 +0000301 GIL
Georg Brandl6c82b6c2007-08-17 16:54:59 +0000302 See :term:`global interpreter lock`.
Georg Brandlc62ef8b2009-01-03 20:55:06 +0000303
Georg Brandl437e6a32007-08-17 06:27:11 +0000304 global interpreter lock
Antoine Pitrou9f41bb32011-01-06 16:35:14 +0000305 The mechanism used by the :term:`CPython` interpreter to assure that
306 only one thread executes Python :term:`bytecode` at a time.
307 This simplifies the CPython implementation by making the object model
308 (including critical built-in types such as :class:`dict`) implicitly
309 safe against concurrent access. Locking the entire interpreter
310 makes it easier for the interpreter to be multi-threaded, at the
311 expense of much of the parallelism afforded by multi-processor
312 machines.
313
314 However, some extension modules, either standard or third-party,
315 are designed so as to release the GIL when doing computationally-intensive
316 tasks such as compression or hashing. Also, the GIL is always released
317 when doing I/O.
318
319 Past efforts to create a "free-threaded" interpreter (one which locks
320 shared data at a much finer granularity) have not been successful
321 because performance suffered in the common single-processor case. It
322 is believed that overcoming this performance issue would make the
323 implementation much more complicated and therefore costlier to maintain.
Georg Brandl7c3e79f2007-11-02 20:06:17 +0000324
325 hashable
Skip Montanarof02c5f32008-09-15 02:03:05 +0000326 An object is *hashable* if it has a hash value which never changes during
Georg Brandl7c3e79f2007-11-02 20:06:17 +0000327 its lifetime (it needs a :meth:`__hash__` method), and can be compared to
328 other objects (it needs an :meth:`__eq__` or :meth:`__cmp__` method).
Skip Montanarof02c5f32008-09-15 02:03:05 +0000329 Hashable objects which compare equal must have the same hash value.
Georg Brandl7c3e79f2007-11-02 20:06:17 +0000330
331 Hashability makes an object usable as a dictionary key and a set member,
332 because these data structures use the hash value internally.
333
Skip Montanarof02c5f32008-09-15 02:03:05 +0000334 All of Python's immutable built-in objects are hashable, while no mutable
335 containers (such as lists or dictionaries) are. Objects which are
Georg Brandl7c3e79f2007-11-02 20:06:17 +0000336 instances of user-defined classes are hashable by default; they all
Ezio Melotti139e4452013-02-01 05:18:44 +0200337 compare unequal (except with themselves), and their hash value is their
338 :func:`id`.
Georg Brandlc62ef8b2009-01-03 20:55:06 +0000339
Georg Brandl437e6a32007-08-17 06:27:11 +0000340 IDLE
341 An Integrated Development Environment for Python. IDLE is a basic editor
Skip Montanarof02c5f32008-09-15 02:03:05 +0000342 and interpreter environment which ships with the standard distribution of
Raymond Hettingerf1b678d2010-09-01 22:25:41 +0000343 Python.
Georg Brandlc62ef8b2009-01-03 20:55:06 +0000344
Georg Brandl437e6a32007-08-17 06:27:11 +0000345 immutable
Skip Montanarof02c5f32008-09-15 02:03:05 +0000346 An object with a fixed value. Immutable objects include numbers, strings and
347 tuples. Such an object cannot be altered. A new object has to
Georg Brandl437e6a32007-08-17 06:27:11 +0000348 be created if a different value has to be stored. They play an important
349 role in places where a constant hash value is needed, for example as a key
350 in a dictionary.
Georg Brandlc62ef8b2009-01-03 20:55:06 +0000351
Georg Brandl437e6a32007-08-17 06:27:11 +0000352 integer division
353 Mathematical division discarding any remainder. For example, the
354 expression ``11/4`` currently evaluates to ``2`` in contrast to the
355 ``2.75`` returned by float division. Also called *floor division*.
356 When dividing two integers the outcome will always be another integer
357 (having the floor function applied to it). However, if one of the operands
358 is another numeric type (such as a :class:`float`), the result will be
Georg Brandl6c82b6c2007-08-17 16:54:59 +0000359 coerced (see :term:`coercion`) to a common type. For example, an integer
Georg Brandl437e6a32007-08-17 06:27:11 +0000360 divided by a float will result in a float value, possibly with a decimal
361 fraction. Integer division can be forced by using the ``//`` operator
Georg Brandl6c82b6c2007-08-17 16:54:59 +0000362 instead of the ``/`` operator. See also :term:`__future__`.
Georg Brandlc62ef8b2009-01-03 20:55:06 +0000363
Georg Brandl624f3372009-03-31 16:11:45 +0000364 importer
365 An object that both finds and loads a module; both a
366 :term:`finder` and :term:`loader` object.
367
Georg Brandl437e6a32007-08-17 06:27:11 +0000368 interactive
Skip Montanarof02c5f32008-09-15 02:03:05 +0000369 Python has an interactive interpreter which means you can enter
370 statements and expressions at the interpreter prompt, immediately
371 execute them and see their results. Just launch ``python`` with no
372 arguments (possibly by selecting it from your computer's main
373 menu). It is a very powerful way to test out new ideas or inspect
374 modules and packages (remember ``help(x)``).
Georg Brandlc62ef8b2009-01-03 20:55:06 +0000375
Georg Brandl437e6a32007-08-17 06:27:11 +0000376 interpreted
Skip Montanarof02c5f32008-09-15 02:03:05 +0000377 Python is an interpreted language, as opposed to a compiled one,
378 though the distinction can be blurry because of the presence of the
379 bytecode compiler. This means that source files can be run directly
380 without explicitly creating an executable which is then run.
381 Interpreted languages typically have a shorter development/debug cycle
382 than compiled ones, though their programs generally also run more
383 slowly. See also :term:`interactive`.
Georg Brandlc62ef8b2009-01-03 20:55:06 +0000384
Georg Brandl437e6a32007-08-17 06:27:11 +0000385 iterable
Chris Jerdonek717e50e2013-01-04 04:41:34 -0800386 An object capable of returning its members one at a time. Examples of
387 iterables include all sequence types (such as :class:`list`, :class:`str`,
388 and :class:`tuple`) and some non-sequence types like :class:`dict`
389 and :class:`file` and objects of any classes you define
390 with an :meth:`__iter__` or :meth:`__getitem__` method. Iterables can be
391 used in a :keyword:`for` loop and in many other places where a sequence is
392 needed (:func:`zip`, :func:`map`, ...). When an iterable object is passed
393 as an argument to the built-in function :func:`iter`, it returns an
394 iterator for the object. This iterator is good for one pass over the set
395 of values. When using iterables, it is usually not necessary to call
396 :func:`iter` or deal with iterator objects yourself. The ``for``
Georg Brandl437e6a32007-08-17 06:27:11 +0000397 statement does that automatically for you, creating a temporary unnamed
398 variable to hold the iterator for the duration of the loop. See also
Georg Brandl6c82b6c2007-08-17 16:54:59 +0000399 :term:`iterator`, :term:`sequence`, and :term:`generator`.
Georg Brandlc62ef8b2009-01-03 20:55:06 +0000400
Georg Brandl437e6a32007-08-17 06:27:11 +0000401 iterator
402 An object representing a stream of data. Repeated calls to the iterator's
403 :meth:`next` method return successive items in the stream. When no more
Skip Montanarof02c5f32008-09-15 02:03:05 +0000404 data are available a :exc:`StopIteration` exception is raised instead. At
Georg Brandl437e6a32007-08-17 06:27:11 +0000405 this point, the iterator object is exhausted and any further calls to its
406 :meth:`next` method just raise :exc:`StopIteration` again. Iterators are
407 required to have an :meth:`__iter__` method that returns the iterator
408 object itself so every iterator is also iterable and may be used in most
409 places where other iterables are accepted. One notable exception is code
Skip Montanarof02c5f32008-09-15 02:03:05 +0000410 which attempts multiple iteration passes. A container object (such as a
Georg Brandl437e6a32007-08-17 06:27:11 +0000411 :class:`list`) produces a fresh new iterator each time you pass it to the
412 :func:`iter` function or use it in a :keyword:`for` loop. Attempting this
413 with an iterator will just return the same exhausted iterator object used
414 in the previous iteration pass, making it appear like an empty container.
Georg Brandlc62ef8b2009-01-03 20:55:06 +0000415
Georg Brandle7a09902007-10-21 12:10:28 +0000416 More information can be found in :ref:`typeiter`.
417
Georg Brandl3b85b9b2010-11-26 08:20:18 +0000418 key function
419 A key function or collation function is a callable that returns a value
420 used for sorting or ordering. For example, :func:`locale.strxfrm` is
421 used to produce a sort key that is aware of locale specific sort
422 conventions.
423
424 A number of tools in Python accept key functions to control how elements
425 are ordered or grouped. They include :func:`min`, :func:`max`,
426 :func:`sorted`, :meth:`list.sort`, :func:`heapq.nsmallest`,
427 :func:`heapq.nlargest`, and :func:`itertools.groupby`.
428
429 There are several ways to create a key function. For example. the
430 :meth:`str.lower` method can serve as a key function for case insensitive
431 sorts. Alternatively, an ad-hoc key function can be built from a
432 :keyword:`lambda` expression such as ``lambda r: (r[0], r[2])``. Also,
Sandro Tosid987c022012-04-01 01:49:46 +0200433 the :mod:`operator` module provides three key function constructors:
Georg Brandl3b85b9b2010-11-26 08:20:18 +0000434 :func:`~operator.attrgetter`, :func:`~operator.itemgetter`, and
435 :func:`~operator.methodcaller`. See the :ref:`Sorting HOW TO
436 <sortinghowto>` for examples of how to create and use key functions.
437
Georg Brandl584265b2007-12-02 14:58:50 +0000438 keyword argument
Chris Jerdonek8da82682012-11-29 19:03:37 -0800439 See :term:`argument`.
Georg Brandl584265b2007-12-02 14:58:50 +0000440
441 lambda
442 An anonymous inline function consisting of a single :term:`expression`
443 which is evaluated when the function is called. The syntax to create
444 a lambda function is ``lambda [arguments]: expression``
445
Georg Brandl437e6a32007-08-17 06:27:11 +0000446 LBYL
447 Look before you leap. This coding style explicitly tests for
448 pre-conditions before making calls or lookups. This style contrasts with
Georg Brandl6c82b6c2007-08-17 16:54:59 +0000449 the :term:`EAFP` approach and is characterized by the presence of many
Georg Brandl437e6a32007-08-17 06:27:11 +0000450 :keyword:`if` statements.
Skip Montanaro9feab312008-09-15 02:19:53 +0000451
Éric Araujoa8f66dd2011-08-19 01:27:00 +0200452 In a multi-threaded environment, the LBYL approach can risk introducing a
453 race condition between "the looking" and "the leaping". For example, the
454 code, ``if key in mapping: return mapping[key]`` can fail if another
455 thread removes *key* from *mapping* after the test, but before the lookup.
456 This issue can be solved with locks or by using the EAFP approach.
457
Skip Montanaro9feab312008-09-15 02:19:53 +0000458 list
459 A built-in Python :term:`sequence`. Despite its name it is more akin
460 to an array in other languages than to a linked list since access to
461 elements are O(1).
Georg Brandlc62ef8b2009-01-03 20:55:06 +0000462
Georg Brandl437e6a32007-08-17 06:27:11 +0000463 list comprehension
Skip Montanarof02c5f32008-09-15 02:03:05 +0000464 A compact way to process all or part of the elements in a sequence and
Georg Brandl437e6a32007-08-17 06:27:11 +0000465 return a list with the results. ``result = ["0x%02x" % x for x in
Skip Montanarof02c5f32008-09-15 02:03:05 +0000466 range(256) if x % 2 == 0]`` generates a list of strings containing
467 even hex numbers (0x..) in the range from 0 to 255. The :keyword:`if`
468 clause is optional. If omitted, all elements in ``range(256)`` are
469 processed.
Georg Brandlc62ef8b2009-01-03 20:55:06 +0000470
Georg Brandl624f3372009-03-31 16:11:45 +0000471 loader
472 An object that loads a module. It must define a method named
473 :meth:`load_module`. A loader is typically returned by a
474 :term:`finder`. See :pep:`302` for details.
475
Georg Brandl437e6a32007-08-17 06:27:11 +0000476 mapping
Raymond Hettingerc4c52dd2011-01-08 23:50:39 +0000477 A container object that supports arbitrary key lookups and implements the
Éric Araujoa8f66dd2011-08-19 01:27:00 +0200478 methods specified in the :class:`~collections.Mapping` or
479 :class:`~collections.MutableMapping`
Éric Araujo8fde9502011-07-29 11:34:17 +0200480 :ref:`abstract base classes <collections-abstract-base-classes>`. Examples
481 include :class:`dict`, :class:`collections.defaultdict`,
Raymond Hettingerc4c52dd2011-01-08 23:50:39 +0000482 :class:`collections.OrderedDict` and :class:`collections.Counter`.
Georg Brandlc62ef8b2009-01-03 20:55:06 +0000483
Georg Brandl437e6a32007-08-17 06:27:11 +0000484 metaclass
485 The class of a class. Class definitions create a class name, a class
486 dictionary, and a list of base classes. The metaclass is responsible for
487 taking those three arguments and creating the class. Most object oriented
488 programming languages provide a default implementation. What makes Python
489 special is that it is possible to create custom metaclasses. Most users
490 never need this tool, but when the need arises, metaclasses can provide
491 powerful, elegant solutions. They have been used for logging attribute
492 access, adding thread-safety, tracking object creation, implementing
493 singletons, and many other tasks.
Georg Brandla7395032007-10-21 12:15:05 +0000494
495 More information can be found in :ref:`metaclasses`.
Georg Brandl584265b2007-12-02 14:58:50 +0000496
497 method
Skip Montanarof02c5f32008-09-15 02:03:05 +0000498 A function which is defined inside a class body. If called as an attribute
Georg Brandl584265b2007-12-02 14:58:50 +0000499 of an instance of that class, the method will get the instance object as
500 its first :term:`argument` (which is usually called ``self``).
501 See :term:`function` and :term:`nested scope`.
Georg Brandlc62ef8b2009-01-03 20:55:06 +0000502
Éric Araujoa8f66dd2011-08-19 01:27:00 +0200503 method resolution order
504 Method Resolution Order is the order in which base classes are searched
505 for a member during lookup. See `The Python 2.3 Method Resolution Order
506 <http://www.python.org/download/releases/2.3/mro/>`_.
507
508 MRO
509 See :term:`method resolution order`.
510
Georg Brandl437e6a32007-08-17 06:27:11 +0000511 mutable
512 Mutable objects can change their value but keep their :func:`id`. See
Georg Brandl6c82b6c2007-08-17 16:54:59 +0000513 also :term:`immutable`.
Georg Brandle3c3db52008-01-11 09:55:53 +0000514
515 named tuple
Raymond Hettingeraff711d2009-02-04 19:25:17 +0000516 Any tuple-like class whose indexable elements are also accessible using
Raymond Hettingerc20ed512008-01-13 06:15:15 +0000517 named attributes (for example, :func:`time.localtime` returns a
Raymond Hettinger8bdd0442008-01-13 06:18:07 +0000518 tuple-like object where the *year* is accessible either with an
Raymond Hettingerc20ed512008-01-13 06:15:15 +0000519 index such as ``t[0]`` or with a named attribute like ``t.tm_year``).
520
521 A named tuple can be a built-in type such as :class:`time.struct_time`,
522 or it can be created with a regular class definition. A full featured
523 named tuple can also be created with the factory function
524 :func:`collections.namedtuple`. The latter approach automatically
525 provides extra features such as a self-documenting representation like
526 ``Employee(name='jones', title='programmer')``.
Georg Brandlc62ef8b2009-01-03 20:55:06 +0000527
Georg Brandl437e6a32007-08-17 06:27:11 +0000528 namespace
529 The place where a variable is stored. Namespaces are implemented as
Georg Brandld7d4fd72009-07-26 14:37:28 +0000530 dictionaries. There are the local, global and built-in namespaces as well
Georg Brandl437e6a32007-08-17 06:27:11 +0000531 as nested namespaces in objects (in methods). Namespaces support
532 modularity by preventing naming conflicts. For instance, the functions
533 :func:`__builtin__.open` and :func:`os.open` are distinguished by their
534 namespaces. Namespaces also aid readability and maintainability by making
535 it clear which module implements a function. For instance, writing
536 :func:`random.seed` or :func:`itertools.izip` makes it clear that those
537 functions are implemented by the :mod:`random` and :mod:`itertools`
Skip Montanarof02c5f32008-09-15 02:03:05 +0000538 modules, respectively.
Georg Brandlc62ef8b2009-01-03 20:55:06 +0000539
Georg Brandl437e6a32007-08-17 06:27:11 +0000540 nested scope
541 The ability to refer to a variable in an enclosing definition. For
542 instance, a function defined inside another function can refer to
Sandro Tosi03c61102012-01-17 18:32:02 +0100543 variables in the outer function. Note that nested scopes work only for
544 reference and not for assignment which will always write to the innermost
545 scope. In contrast, local variables both read and write in the innermost
546 scope. Likewise, global variables read and write to the global namespace.
Georg Brandlc62ef8b2009-01-03 20:55:06 +0000547
Georg Brandl437e6a32007-08-17 06:27:11 +0000548 new-style class
Skip Montanarof02c5f32008-09-15 02:03:05 +0000549 Any class which inherits from :class:`object`. This includes all built-in
Georg Brandl437e6a32007-08-17 06:27:11 +0000550 types like :class:`list` and :class:`dict`. Only new-style classes can
551 use Python's newer, versatile features like :attr:`__slots__`,
Skip Montanarof02c5f32008-09-15 02:03:05 +0000552 descriptors, properties, and :meth:`__getattribute__`.
Georg Brandla7395032007-10-21 12:15:05 +0000553
554 More information can be found in :ref:`newstyle`.
Skip Montanaro9feab312008-09-15 02:19:53 +0000555
556 object
557 Any data with state (attributes or value) and defined behavior
558 (methods). Also the ultimate base class of any :term:`new-style
559 class`.
Georg Brandlc62ef8b2009-01-03 20:55:06 +0000560
Chris Jerdonek8da82682012-11-29 19:03:37 -0800561 parameter
562 A named entity in a :term:`function` (or method) definition that
563 specifies an :term:`argument` (or in some cases, arguments) that the
564 function can accept. There are four types of parameters:
565
566 * :dfn:`positional-or-keyword`: specifies an argument that can be passed
567 either :term:`positionally <argument>` or as a :term:`keyword argument
568 <argument>`. This is the default kind of parameter, for example *foo*
569 and *bar* in the following::
570
571 def func(foo, bar=None): ...
572
573 * :dfn:`positional-only`: specifies an argument that can be supplied only
574 by position. Python has no syntax for defining positional-only
575 parameters. However, some built-in functions have positional-only
576 parameters (e.g. :func:`abs`).
577
578 * :dfn:`var-positional`: specifies that an arbitrary sequence of
579 positional arguments can be provided (in addition to any positional
580 arguments already accepted by other parameters). Such a parameter can
581 be defined by prepending the parameter name with ``*``, for example
582 *args* in the following::
583
584 def func(*args, **kwargs): ...
585
586 * :dfn:`var-keyword`: specifies that arbitrarily many keyword arguments
587 can be provided (in addition to any keyword arguments already accepted
588 by other parameters). Such a parameter can be defined by prepending
589 the parameter name with ``**``, for example *kwargs* in the example
590 above.
591
592 Parameters can specify both optional and required arguments, as well as
593 default values for some optional arguments.
594
595 See also the :term:`argument` glossary entry, the FAQ question on
596 :ref:`the difference between arguments and parameters
597 <faq-argument-vs-parameter>`, and the :ref:`function` section.
598
Georg Brandl584265b2007-12-02 14:58:50 +0000599 positional argument
Chris Jerdonek8da82682012-11-29 19:03:37 -0800600 See :term:`argument`.
Georg Brandl584265b2007-12-02 14:58:50 +0000601
Georg Brandlc62ef8b2009-01-03 20:55:06 +0000602 Python 3000
Éric Araujoa8f66dd2011-08-19 01:27:00 +0200603 Nickname for the Python 3.x release line (coined long ago when the release
604 of version 3 was something in the distant future.) This is also
605 abbreviated "Py3k".
Georg Brandl437e6a32007-08-17 06:27:11 +0000606
Georg Brandl584265b2007-12-02 14:58:50 +0000607 Pythonic
Skip Montanarof02c5f32008-09-15 02:03:05 +0000608 An idea or piece of code which closely follows the most common idioms
609 of the Python language, rather than implementing code using concepts
610 common to other languages. For example, a common idiom in Python is
611 to loop over all elements of an iterable using a :keyword:`for`
612 statement. Many other languages don't have this type of construct, so
613 people unfamiliar with Python sometimes use a numerical counter instead::
Georg Brandlc62ef8b2009-01-03 20:55:06 +0000614
Georg Brandl584265b2007-12-02 14:58:50 +0000615 for i in range(len(food)):
616 print food[i]
617
618 As opposed to the cleaner, Pythonic method::
619
620 for piece in food:
621 print piece
622
Georg Brandl437e6a32007-08-17 06:27:11 +0000623 reference count
Skip Montanarof02c5f32008-09-15 02:03:05 +0000624 The number of references to an object. When the reference count of an
625 object drops to zero, it is deallocated. Reference counting is
626 generally not visible to Python code, but it is a key element of the
627 :term:`CPython` implementation. The :mod:`sys` module defines a
Éric Araujoa8f66dd2011-08-19 01:27:00 +0200628 :func:`~sys.getrefcount` function that programmers can call to return the
Skip Montanarof02c5f32008-09-15 02:03:05 +0000629 reference count for a particular object.
630
Georg Brandl437e6a32007-08-17 06:27:11 +0000631 __slots__
Georg Brandl6c82b6c2007-08-17 16:54:59 +0000632 A declaration inside a :term:`new-style class` that saves memory by
Georg Brandl437e6a32007-08-17 06:27:11 +0000633 pre-declaring space for instance attributes and eliminating instance
634 dictionaries. Though popular, the technique is somewhat tricky to get
635 right and is best reserved for rare cases where there are large numbers of
636 instances in a memory-critical application.
Georg Brandlc62ef8b2009-01-03 20:55:06 +0000637
Georg Brandl437e6a32007-08-17 06:27:11 +0000638 sequence
Georg Brandl6c82b6c2007-08-17 16:54:59 +0000639 An :term:`iterable` which supports efficient element access using integer
Skip Montanarof02c5f32008-09-15 02:03:05 +0000640 indices via the :meth:`__getitem__` special method and defines a
641 :meth:`len` method that returns the length of the sequence.
Georg Brandl437e6a32007-08-17 06:27:11 +0000642 Some built-in sequence types are :class:`list`, :class:`str`,
643 :class:`tuple`, and :class:`unicode`. Note that :class:`dict` also
644 supports :meth:`__getitem__` and :meth:`__len__`, but is considered a
645 mapping rather than a sequence because the lookups use arbitrary
Georg Brandl6c82b6c2007-08-17 16:54:59 +0000646 :term:`immutable` keys rather than integers.
Georg Brandl437e6a32007-08-17 06:27:11 +0000647
Georg Brandl584265b2007-12-02 14:58:50 +0000648 slice
Georg Brandl968a3e52007-12-02 18:17:50 +0000649 An object usually containing a portion of a :term:`sequence`. A slice is
Georg Brandl584265b2007-12-02 14:58:50 +0000650 created using the subscript notation, ``[]`` with colons between numbers
651 when several are given, such as in ``variable_name[1:3:5]``. The bracket
652 (subscript) notation uses :class:`slice` objects internally (or in older
653 versions, :meth:`__getslice__` and :meth:`__setslice__`).
654
Georg Brandl9a053732008-12-05 15:29:39 +0000655 special method
656 A method that is called implicitly by Python to execute a certain
657 operation on a type, such as addition. Such methods have names starting
658 and ending with double underscores. Special methods are documented in
659 :ref:`specialnames`.
660
Georg Brandl584265b2007-12-02 14:58:50 +0000661 statement
662 A statement is part of a suite (a "block" of code). A statement is either
663 an :term:`expression` or a one of several constructs with a keyword, such
Éric Araujoa8f66dd2011-08-19 01:27:00 +0200664 as :keyword:`if`, :keyword:`while` or :keyword:`for`.
665
666 struct sequence
667 A tuple with named elements. Struct sequences expose an interface similiar
668 to :term:`named tuple` in that elements can either be accessed either by
669 index or as an attribute. However, they do not have any of the named tuple
670 methods like :meth:`~collections.somenamedtuple._make` or
671 :meth:`~collections.somenamedtuple._asdict`. Examples of struct sequences
672 include :data:`sys.float_info` and the return value of :func:`os.stat`.
Georg Brandl584265b2007-12-02 14:58:50 +0000673
Skip Montanaro9feab312008-09-15 02:19:53 +0000674 triple-quoted string
675 A string which is bound by three instances of either a quotation mark
676 (") or an apostrophe ('). While they don't provide any functionality
677 not available with single-quoted strings, they are useful for a number
678 of reasons. They allow you to include unescaped single and double
679 quotes within a string and they can span multiple lines without the
680 use of the continuation character, making them especially useful when
681 writing docstrings.
682
Georg Brandl437e6a32007-08-17 06:27:11 +0000683 type
684 The type of a Python object determines what kind of object it is; every
685 object has a type. An object's type is accessible as its
686 :attr:`__class__` attribute or can be retrieved with ``type(obj)``.
Skip Montanarof02c5f32008-09-15 02:03:05 +0000687
R David Murray5618aaa2012-08-15 11:15:39 -0400688 universal newlines
689 A manner of interpreting text streams in which all of the following are
690 recognized as ending a line: the Unix end-of-line convention ``'\n'``,
691 the Windows convention ``'\r\n'``, and the old Macintosh convention
692 ``'\r'``. See :pep:`278` and :pep:`3116`, as well as
693 :func:`str.splitlines` for an additional use.
694
Alexandre Vassalotti69eb5162010-01-11 23:17:10 +0000695 view
696 The objects returned from :meth:`dict.viewkeys`, :meth:`dict.viewvalues`,
697 and :meth:`dict.viewitems` are called dictionary views. They are lazy
698 sequences that will see changes in the underlying dictionary. To force
699 the dictionary view to become a full list use ``list(dictview)``. See
700 :ref:`dict-views`.
701
Skip Montanarof02c5f32008-09-15 02:03:05 +0000702 virtual machine
703 A computer defined entirely in software. Python's virtual machine
704 executes the :term:`bytecode` emitted by the bytecode compiler.
Georg Brandlc62ef8b2009-01-03 20:55:06 +0000705
Georg Brandl437e6a32007-08-17 06:27:11 +0000706 Zen of Python
707 Listing of Python design principles and philosophies that are helpful in
708 understanding and using the language. The listing can be found by typing
709 "``import this``" at the interactive prompt.