12
The typical Python prompt of the interactive shell. Often seen for code
13
examples that can be tried right away in the interpreter.
12
The default Python prompt of the interactive shell. Often seen for code
13
examples which can be executed interactively in the interpreter.
16
The typical Python prompt of the interactive shell when entering code for
17
an indented code block.
16
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).
20
21
A tool that tries to convert Python 2.x code to Python 3.x code by
21
handling most of the incompatibilites that can be detected by parsing the
22
handling most of the incompatibilites which can be detected by parsing the
22
23
source and traversing the parse tree.
24
25
2to3 is available in the standard library as :mod:`lib2to3`; a standalone
25
entry point is provided as :file:`Tools/scripts/2to3`.
26
entry point is provided as :file:`Tools/scripts/2to3`. See
27
:ref:`2to3-reference`.
30
Abstract Base Classes (abbreviated ABCs) complement :term:`duck-typing` by
31
providing a way to define interfaces when other techniques like :func:`hasattr`
32
would be clumsy. Python comes with many builtin ABCs for data structures
33
(in the :mod:`collections` module), numbers (in the :mod:`numbers`
34
module), and streams (in the :mod:`io` module). You can create your own
35
ABC with the :mod:`abc` module.
28
A value passed to a function or method, assigned to a name local to
29
the body. A function or method may have both positional arguments and
30
keyword arguments in its definition. Positional and keyword arguments
31
may be variable-length: ``*`` accepts or passes (if in the function
32
definition or call) several positional arguments in a list, while ``**``
33
does the same for keyword arguments in a dictionary.
38
A value passed to a function or method, assigned to a named local
39
variable in the function body. A function or method may have both
40
positional arguments and keyword arguments in its definition.
41
Positional and keyword arguments may be variable-length: ``*`` accepts
42
or passes (if in the function definition or call) several positional
43
arguments in a list, while ``**`` does the same for keyword arguments
35
46
Any expression may be used within the argument list, and the evaluated
36
47
value is passed to the local variable.
50
A value associated with an object which is referenced by name using
51
dotted expressions. For example, if an object *o* has an attribute
52
*a* it would be referenced as *o.a*.
39
55
Benevolent Dictator For Life, a.k.a. `Guido van Rossum
44
60
of a Python program in the interpreter. The bytecode is also cached in
45
61
``.pyc`` and ``.pyo`` files so that executing the same file is faster the
46
62
second time (recompilation from source to bytecode can be avoided). This
47
"intermediate language" is said to run on a "virtual machine" that calls
48
the subroutines corresponding to each bytecode.
63
"intermediate language" is said to run on a :term:`virtual machine`
64
that executes the machine code corresponding to each bytecode.
67
A template for creating user-defined objects. Class definitions
68
normally contain method definitions which operate on instances of the
51
72
Any class which does not inherit from :class:`object`. See
52
:term:`new-style class`.
73
:term:`new-style class`. Classic classes will be removed in Python 3.0.
55
76
The implicit conversion of an instance of one type to another during an
77
98
it's almost certain you can safely ignore them.
80
An objects that controls the environment seen in a :keyword:`with`
101
An object which controls the environment seen in a :keyword:`with`
81
102
statement by defining :meth:`__enter__` and :meth:`__exit__` methods.
106
The canonical implementation of the Python programming language. The
107
term "CPython" is used in contexts when necessary to distinguish this
108
implementation from others such as Jython or IronPython.
85
111
A function returning another function, usually applied as a function
86
112
transformation using the ``@wrapper`` syntax. Common examples for
114
140
An associative array, where arbitrary keys are mapped to values. The use
115
of :class:`dict` much resembles that for :class:`list`, but the keys can
116
be any object with a :meth:`__hash__` function, not just integers starting
117
from zero. Called a hash in Perl.
141
of :class:`dict` closely resembles that for :class:`list`, but the keys can
142
be any object with a :meth:`__hash__` function, not just integers.
143
Called a hash in Perl.
146
A string literal which appears as the first expression in a class,
147
function or module. While ignored when the suite is executed, it is
148
recognized by the compiler and put into the :attr:`__doc__` attribute
149
of the enclosing class, function or module. Since it is available via
150
introspection, it is the canonical place for documentation of the
120
Pythonic programming style that determines an object's type by inspection
154
A pythonic programming style which determines an object's type by inspection
121
155
of its method or attribute signature rather than by explicit relationship
122
156
to some type object ("If it looks like a duck and quacks like a duck, it
123
157
must be a duck.") By emphasizing interfaces rather than specific types,
124
158
well-designed code improves its flexibility by allowing polymorphic
125
159
substitution. Duck-typing avoids tests using :func:`type` or
126
:func:`isinstance`. Instead, it typically employs :func:`hasattr` tests or
127
:term:`EAFP` programming.
160
:func:`isinstance`. (Note, however, that duck-typing can be complemented
161
with abstract base classes.) Instead, it typically employs :func:`hasattr`
162
tests or :term:`EAFP` programming.
130
165
Easier to ask for forgiveness than permission. This common Python coding
131
166
style assumes the existence of valid keys or attributes and catches
132
167
exceptions if the assumption proves false. This clean and fast style is
133
168
characterized by the presence of many :keyword:`try` and :keyword:`except`
134
statements. The technique contrasts with the :term:`LBYL` style that is
135
common in many other languages such as C.
169
statements. The technique contrasts with the :term:`LBYL` style
170
common to many other languages such as C.
138
173
A piece of syntax which can be evaluated to some value. In other words,
139
174
an expression is an accumulation of expression elements like literals, names,
140
attribute access, operators or function calls that all return a value.
141
In contrast to other languages, not all language constructs are expressions,
142
but there are also :term:`statement`\s that cannot be used as expressions,
143
such as :keyword:`print` or :keyword:`if`. Assignments are also not
175
attribute access, operators or function calls which all return a value.
176
In contrast to many other languages, not all language constructs are expressions.
177
There are also :term:`statement`\s which cannot be used as expressions,
178
such as :keyword:`print` or :keyword:`if`. Assignments are also statements,
147
A module written in C, using Python's C API to interact with the core and
182
A module written in C or C++, using Python's C API to interact with the core and
175
210
collector that is able to detect and break reference cycles.
178
A function that returns an iterator. It looks like a normal function
213
A function which returns an iterator. It looks like a normal function
179
214
except that values are returned to the caller using a :keyword:`yield`
180
215
statement instead of a :keyword:`return` statement. Generator functions
181
often contain one or more :keyword:`for` or :keyword:`while` loops that
216
often contain one or more :keyword:`for` or :keyword:`while` loops which
182
217
:keyword:`yield` elements back to the caller. The function execution is
183
218
stopped at the :keyword:`yield` keyword (returning the result) and is
184
219
resumed there when the next element is requested by calling the
199
234
See :term:`global interpreter lock`.
201
236
global interpreter lock
202
The lock used by Python threads to assure that only one thread can be run
203
at a time. This simplifies Python by assuring that no two processes can
204
access the same memory at the same time. Locking the entire interpreter
205
makes it easier for the interpreter to be multi-threaded, at the expense
206
of some parallelism on multi-processor machines. Efforts have been made
207
in the past to create a "free-threaded" interpreter (one which locks
208
shared data at a much finer granularity), but performance suffered in the
209
common single-processor case.
237
The lock used by Python threads to assure that only one thread
238
executes in the :term:`CPython` :term:`virtual machine` at a time.
239
This simplifies the CPython implementation by assuring that no two
240
processes can access the same memory at the same time. Locking the
241
entire interpreter makes it easier for the interpreter to be
242
multi-threaded, at the expense of much of the parallelism afforded by
243
multi-processor machines. Efforts have been made in the past to
244
create a "free-threaded" interpreter (one which locks shared data at a
245
much finer granularity), but so far none have been successful because
246
performance suffered in the common single-processor case.
212
An object is *hashable* if it has a hash value that never changes during
249
An object is *hashable* if it has a hash value which never changes during
213
250
its lifetime (it needs a :meth:`__hash__` method), and can be compared to
214
251
other objects (it needs an :meth:`__eq__` or :meth:`__cmp__` method).
215
Hashable objects that compare equal must have the same hash value.
252
Hashable objects which compare equal must have the same hash value.
217
254
Hashability makes an object usable as a dictionary key and a set member,
218
255
because these data structures use the hash value internally.
220
All of Python's immutable built-in objects are hashable, while all mutable
221
containers (such as lists or dictionaries) are not. Objects that are
257
All of Python's immutable built-in objects are hashable, while no mutable
258
containers (such as lists or dictionaries) are. Objects which are
222
259
instances of user-defined classes are hashable by default; they all
223
260
compare unequal, and their hash value is their :func:`id`.
226
263
An Integrated Development Environment for Python. IDLE is a basic editor
227
and interpreter environment that ships with the standard distribution of
264
and interpreter environment which ships with the standard distribution of
228
265
Python. Good for beginners, it also serves as clear example code for
229
266
those wanting to implement a moderately sophisticated, multi-platform GUI
233
An object with fixed value. Immutable objects are numbers, strings or
234
tuples (and more). Such an object cannot be altered. A new object has to
270
An object with a fixed value. Immutable objects include numbers, strings and
271
tuples. Such an object cannot be altered. A new object has to
235
272
be created if a different value has to be stored. They play an important
236
273
role in places where a constant hash value is needed, for example as a key
249
286
instead of the ``/`` operator. See also :term:`__future__`.
252
Python has an interactive interpreter which means that you can try out
253
things and immediately see their results. Just launch ``python`` with no
254
arguments (possibly by selecting it from your computer's main menu). It is
255
a very powerful way to test out new ideas or inspect modules and packages
256
(remember ``help(x)``).
289
Python has an interactive interpreter which means you can enter
290
statements and expressions at the interpreter prompt, immediately
291
execute them and see their results. Just launch ``python`` with no
292
arguments (possibly by selecting it from your computer's main
293
menu). It is a very powerful way to test out new ideas or inspect
294
modules and packages (remember ``help(x)``).
259
Python is an interpreted language, as opposed to a compiled one. This
260
means that the source files can be run directly without first creating an
261
executable which is then run. Interpreted languages typically have a
262
shorter development/debug cycle than compiled ones, though their programs
263
generally also run more slowly. See also :term:`interactive`.
297
Python is an interpreted language, as opposed to a compiled one,
298
though the distinction can be blurry because of the presence of the
299
bytecode compiler. This means that source files can be run directly
300
without explicitly creating an executable which is then run.
301
Interpreted languages typically have a shorter development/debug cycle
302
than compiled ones, though their programs generally also run more
303
slowly. See also :term:`interactive`.
266
306
A container object capable of returning its members one at a
282
322
An object representing a stream of data. Repeated calls to the iterator's
283
323
:meth:`next` method return successive items in the stream. When no more
284
data is available a :exc:`StopIteration` exception is raised instead. At
324
data are available a :exc:`StopIteration` exception is raised instead. At
285
325
this point, the iterator object is exhausted and any further calls to its
286
326
:meth:`next` method just raise :exc:`StopIteration` again. Iterators are
287
327
required to have an :meth:`__iter__` method that returns the iterator
288
328
object itself so every iterator is also iterable and may be used in most
289
329
places where other iterables are accepted. One notable exception is code
290
that attempts multiple iteration passes. A container object (such as a
330
which attempts multiple iteration passes. A container object (such as a
291
331
:class:`list`) produces a fresh new iterator each time you pass it to the
292
332
:func:`iter` function or use it in a :keyword:`for` loop. Attempting this
293
333
with an iterator will just return the same exhausted iterator object used
311
351
pre-conditions before making calls or lookups. This style contrasts with
312
352
the :term:`EAFP` approach and is characterized by the presence of many
313
353
:keyword:`if` statements.
356
A built-in Python :term:`sequence`. Despite its name it is more akin
357
to an array in other languages than to a linked list since access to
315
360
list comprehension
316
A compact way to process all or a subset of elements in a sequence and
361
A compact way to process all or part of the elements in a sequence and
317
362
return a list with the results. ``result = ["0x%02x" % x for x in
318
range(256) if x % 2 == 0]`` generates a list of strings containing hex
319
numbers (0x..) that are even and in the range from 0 to 255. The
320
:keyword:`if` clause is optional. If omitted, all elements in
321
``range(256)`` are processed.
363
range(256) if x % 2 == 0]`` generates a list of strings containing
364
even hex numbers (0x..) in the range from 0 to 255. The :keyword:`if`
365
clause is optional. If omitted, all elements in ``range(256)`` are
324
A container object (such as :class:`dict`) that supports arbitrary key
369
A container object (such as :class:`dict`) which supports arbitrary key
325
370
lookups using the special method :meth:`__getitem__`.
381
426
scope. Likewise, global variables read and write to the global namespace.
384
Any class that inherits from :class:`object`. This includes all built-in
429
Any class which inherits from :class:`object`. This includes all built-in
385
430
types like :class:`list` and :class:`dict`. Only new-style classes can
386
431
use Python's newer, versatile features like :attr:`__slots__`,
387
descriptors, properties, :meth:`__getattribute__`, class methods, and
432
descriptors, properties, and :meth:`__getattribute__`.
390
434
More information can be found in :ref:`newstyle`.
437
Any data with state (attributes or value) and defined behavior
438
(methods). Also the ultimate base class of any :term:`new-style
392
441
positional argument
393
442
The arguments assigned to local names inside a function or method,
402
451
is also abbreviated "Py3k".
405
An idea or piece of code which closely follows the most common idioms of
406
the Python language, rather than implementing code using concepts common
407
in other languages. For example, a common idiom in Python is the :keyword:`for`
408
loop structure; other languages don't have this easy keyword, so people
409
use a numerical counter instead::
454
An idea or piece of code which closely follows the most common idioms
455
of the Python language, rather than implementing code using concepts
456
common to other languages. For example, a common idiom in Python is
457
to loop over all elements of an iterable using a :keyword:`for`
458
statement. Many other languages don't have this type of construct, so
459
people unfamiliar with Python sometimes use a numerical counter instead::
411
461
for i in range(len(food)):
420
The number of places where a certain object is referenced to. When the
421
reference count drops to zero, an object is deallocated. While reference
422
counting is invisible on the Python code level, it is used on the
423
implementation level to keep track of allocated memory.
470
The number of references to an object. When the reference count of an
471
object drops to zero, it is deallocated. Reference counting is
472
generally not visible to Python code, but it is a key element of the
473
:term:`CPython` implementation. The :mod:`sys` module defines a
474
:func:`getrefcount` function that programmers can call to return the
475
reference count for a particular object.
426
478
A declaration inside a :term:`new-style class` that saves memory by
427
479
pre-declaring space for instance attributes and eliminating instance
433
485
An :term:`iterable` which supports efficient element access using integer
434
indices via the :meth:`__getitem__` and :meth:`__len__` special methods.
486
indices via the :meth:`__getitem__` special method and defines a
487
:meth:`len` method that returns the length of the sequence.
435
488
Some built-in sequence types are :class:`list`, :class:`str`,
436
489
:class:`tuple`, and :class:`unicode`. Note that :class:`dict` also
437
490
supports :meth:`__getitem__` and :meth:`__len__`, but is considered a
450
503
an :term:`expression` or a one of several constructs with a keyword, such
451
504
as :keyword:`if`, :keyword:`while` or :keyword:`print`.
507
A string which is bound by three instances of either a quotation mark
508
(") or an apostrophe ('). While they don't provide any functionality
509
not available with single-quoted strings, they are useful for a number
510
of reasons. They allow you to include unescaped single and double
511
quotes within a string and they can span multiple lines without the
512
use of the continuation character, making them especially useful when
454
516
The type of a Python object determines what kind of object it is; every
455
517
object has a type. An object's type is accessible as its
456
518
:attr:`__class__` attribute or can be retrieved with ``type(obj)``.
521
A computer defined entirely in software. Python's virtual machine
522
executes the :term:`bytecode` emitted by the bytecode compiler.
459
525
Listing of Python design principles and philosophies that are helpful in