Skip Montanaro | 757dedc | 2003-09-24 16:51:23 +0000 | [diff] [blame] | 1 | \chapter{Glossary\label{glossary}} |
| 2 | |
| 3 | %%% keep the entries sorted and include at least one \index{} item for each |
Raymond Hettinger | 5a25aa6 | 2003-09-27 05:42:14 +0000 | [diff] [blame] | 4 | %%% cross-references are marked with \emph{entry} |
Skip Montanaro | 757dedc | 2003-09-24 16:51:23 +0000 | [diff] [blame] | 5 | |
| 6 | \begin{description} |
| 7 | |
Skip Montanaro | 757dedc | 2003-09-24 16:51:23 +0000 | [diff] [blame] | 8 | |
| 9 | \index{>>>} |
Fred Drake | d4a1419 | 2003-09-27 18:59:43 +0000 | [diff] [blame] | 10 | \item[\code{>\code{>}>}] |
| 11 | The typical Python prompt of the interactive shell. Often seen for |
| 12 | code examples that can be tried right away in the interpreter. |
Skip Montanaro | 757dedc | 2003-09-24 16:51:23 +0000 | [diff] [blame] | 13 | |
Raymond Hettinger | 43b5e40 | 2003-09-27 20:19:02 +0000 | [diff] [blame] | 14 | \index{...} |
| 15 | \item[\code{.\code{.}.}] |
| 16 | The typical Python prompt of the interactive shell when entering code |
| 17 | for an indented code block. |
Skip Montanaro | 757dedc | 2003-09-24 16:51:23 +0000 | [diff] [blame] | 18 | |
| 19 | \index{BDFL} |
Fred Drake | d4a1419 | 2003-09-27 18:59:43 +0000 | [diff] [blame] | 20 | \item[BDFL] |
| 21 | Benevolent Dictator For Life, a.k.a. \ulink{Guido van |
Raymond Hettinger | 43b5e40 | 2003-09-27 20:19:02 +0000 | [diff] [blame] | 22 | Rossum}{http://www.python.org/\textasciitilde{}guido/}, Python's creator. |
Skip Montanaro | 757dedc | 2003-09-24 16:51:23 +0000 | [diff] [blame] | 23 | |
| 24 | \index{byte code} |
Fred Drake | d4a1419 | 2003-09-27 18:59:43 +0000 | [diff] [blame] | 25 | \item[byte code] |
| 26 | The internal representation of a Python program in the interpreter. |
| 27 | The byte code is also cached in the \code{.pyc} and \code{.pyo} |
| 28 | files so that executing the same file is faster the second time |
| 29 | (compilation from source to byte code can be saved). This |
Raymond Hettinger | 43b5e40 | 2003-09-27 20:19:02 +0000 | [diff] [blame] | 30 | ``intermediate language'' is said to run on a ``virtual |
| 31 | machine'' that calls the subroutines corresponding to each bytecode. |
Skip Montanaro | 757dedc | 2003-09-24 16:51:23 +0000 | [diff] [blame] | 32 | |
| 33 | \index{classic class} |
Fred Drake | d4a1419 | 2003-09-27 18:59:43 +0000 | [diff] [blame] | 34 | \item[classic class] |
| 35 | Any class which does not inherit from \class{object}. See |
| 36 | \emph{new-style class}. |
Skip Montanaro | 757dedc | 2003-09-24 16:51:23 +0000 | [diff] [blame] | 37 | |
| 38 | \index{coercion} |
Fred Drake | d4a1419 | 2003-09-27 18:59:43 +0000 | [diff] [blame] | 39 | \item[coercion] |
Skip Montanaro | dbb4078 | 2004-03-27 18:23:11 +0000 | [diff] [blame] | 40 | |
| 41 | The implicit conversion of an instance of one type to another during an |
| 42 | operation which involves two arguments of the same type. For example, |
| 43 | {}\code{int(3.15)} converts the floating point number to the integer, |
| 44 | {}\code{3}, but in {}\code{3+4.5}, each argument is of a different type (one |
| 45 | int, one float), and both must be converted to the same type before they can |
| 46 | be added or it will raise a {}\code{TypeError}. Coercion between two |
| 47 | operands can be performed with the {}\code{coerce} builtin function; thus, |
| 48 | {}\code{3+4.5} is equivalent to calling {}\code{operator.add(*coerce(3, |
| 49 | 4.5))} and results in {}\code{operator.add(3.0, 4.5)}. Without coercion, |
| 50 | all arguments of even compatible types would have to be normalized to the |
| 51 | same value by the programmer, e.g., {}\code{float(3)+4.5} rather than just |
| 52 | {}\code{3+4.5}. |
| 53 | |
| 54 | \index{complex number} |
| 55 | \item[complex number] |
| 56 | |
| 57 | An extension of the familiar real number system in which all numbers are |
| 58 | expressed as a sum of a real part and an imaginary part. Imaginary numbers |
| 59 | are real multiples of the imaginary unit (the square root of {}\code{-1}), |
| 60 | often written {}\code{i} in mathematics or {}\code{j} in engineering. |
| 61 | Python has builtin support for complex numbers, which are written with this |
| 62 | latter notation; the imaginary part is written with a {}\code{j} suffix, |
| 63 | e.g., {}\code{3+1j}. To get access to complex equivalents of the |
| 64 | {}\module{math} module, use {}\module{cmath}. Use of complex numbers is a |
Andrew M. Kuchling | aeaec8d | 2004-03-29 01:19:54 +0000 | [diff] [blame] | 65 | fairly advanced mathematical feature. If you're not aware of a need for them, |
Raymond Hettinger | f13c024 | 2004-03-28 22:44:09 +0000 | [diff] [blame] | 66 | it's almost certain you can safely ignore them. |
Skip Montanaro | 757dedc | 2003-09-24 16:51:23 +0000 | [diff] [blame] | 67 | |
| 68 | \index{descriptor} |
Fred Drake | d4a1419 | 2003-09-27 18:59:43 +0000 | [diff] [blame] | 69 | \item[descriptor] |
| 70 | Any \emph{new-style} object that defines the methods |
| 71 | {}\method{__get__()}, \method{__set__()}, or \method{__delete__()}. |
| 72 | When a class attribute is a descriptor, its special binding behavior |
| 73 | is triggered upon attribute lookup. Normally, writing \var{a.b} looks |
| 74 | up the object \var{b} in the class dictionary for \var{a}, but if |
| 75 | {}\var{b} is a descriptor, the defined method gets called. |
| 76 | Understanding descriptors is a key to a deep understanding of Python |
| 77 | because they are the basis for many features including functions, |
| 78 | methods, properties, class methods, static methods, and reference to |
| 79 | super classes. |
Skip Montanaro | 757dedc | 2003-09-24 16:51:23 +0000 | [diff] [blame] | 80 | |
| 81 | \index{dictionary} |
Fred Drake | d4a1419 | 2003-09-27 18:59:43 +0000 | [diff] [blame] | 82 | \item[dictionary] |
| 83 | An associative array, where arbitrary keys are mapped to values. The |
| 84 | use of \class{dict} much resembles that for \class{list}, but the keys |
| 85 | can be any object with a \method{__hash__()} function, not just |
| 86 | integers starting from zero. Called a hash in Perl. |
Skip Montanaro | 757dedc | 2003-09-24 16:51:23 +0000 | [diff] [blame] | 87 | |
| 88 | \index{EAFP} |
Fred Drake | d4a1419 | 2003-09-27 18:59:43 +0000 | [diff] [blame] | 89 | \item[EAFP] |
| 90 | Easier to ask for forgiveness than permission. This common Python |
| 91 | coding style assumes the existence of valid keys or attributes and |
| 92 | catches exceptions if the assumption proves false. This clean and |
| 93 | fast style is characterized by the presence of many \keyword{try} and |
| 94 | {}\keyword{except} statements. The technique contrasts with the |
| 95 | {}\emph{LBYL} style that is common in many other languages such as C. |
Skip Montanaro | 757dedc | 2003-09-24 16:51:23 +0000 | [diff] [blame] | 96 | |
| 97 | \index{__future__} |
Fred Drake | d4a1419 | 2003-09-27 18:59:43 +0000 | [diff] [blame] | 98 | \item[__future__] |
| 99 | A pseudo module which programmers can use to enable new language |
| 100 | features which are not compatible with the current interpreter. For |
Raymond Hettinger | 43b5e40 | 2003-09-27 20:19:02 +0000 | [diff] [blame] | 101 | example, the expression \code{11/4} currently evaluates to \code{2}. |
| 102 | If the module in which it is executed had enabled \emph{true division} |
Fred Drake | d4a1419 | 2003-09-27 18:59:43 +0000 | [diff] [blame] | 103 | by executing: |
Skip Montanaro | 757dedc | 2003-09-24 16:51:23 +0000 | [diff] [blame] | 104 | |
| 105 | \begin{verbatim} |
| 106 | from __future__ import division |
| 107 | \end{verbatim} |
| 108 | |
Fred Drake | 984920b | 2003-09-28 19:03:36 +0000 | [diff] [blame] | 109 | the expression \code{11/4} would evaluate to \code{2.75}. By actually |
| 110 | importing the \ulink{\module{__future__}}{../lib/module-future.html} |
| 111 | module and evaluating its variables, you can see when a new feature |
| 112 | was first added to the language and when it will become the default: |
Skip Montanaro | 757dedc | 2003-09-24 16:51:23 +0000 | [diff] [blame] | 113 | |
| 114 | \begin{verbatim} |
| 115 | >>> import __future__ |
| 116 | >>> __future__.division |
| 117 | _Feature((2, 2, 0, 'alpha', 2), (3, 0, 0, 'alpha', 0), 8192) |
| 118 | \end{verbatim} |
| 119 | |
| 120 | \index{generator} |
Fred Drake | d4a1419 | 2003-09-27 18:59:43 +0000 | [diff] [blame] | 121 | \item[generator] |
Skip Montanaro | dbb4078 | 2004-03-27 18:23:11 +0000 | [diff] [blame] | 122 | A function that returns an iterator. It looks like a normal function except |
| 123 | that values are returned to the caller using a \keyword{yield} statement |
| 124 | instead of a {}\keyword{return} statement. Generator functions often |
| 125 | contain one or more {}\keyword{for} or \keyword{while} loops that |
| 126 | \keyword{yield} elements back to the caller. The function execution is |
| 127 | stopped at the {}\keyword{yield} keyword (returning the result) and is |
| 128 | resumed there when the next element is requested by calling the |
| 129 | \method{next()} method of the returned iterator. |
Skip Montanaro | 757dedc | 2003-09-24 16:51:23 +0000 | [diff] [blame] | 130 | |
Raymond Hettinger | d348193 | 2004-06-07 21:52:47 +0000 | [diff] [blame] | 131 | \index{generator expression} |
| 132 | \item[generator expression] |
| 133 | An expression that returns a generator. It looks like a normal expression |
| 134 | followed by a \keyword{for} expression defining a loop variable, range, and |
| 135 | an optional \keyword{if} expression. The combined expression generates |
| 136 | values for an enclosing function: |
| 137 | |
| 138 | \begin{verbatim} |
| 139 | >>> sum(i*i for i in range(10)) # sum of squares 0, 1, 4, ... 81 |
| 140 | 285 |
| 141 | \end{verbatim} |
| 142 | |
Skip Montanaro | 757dedc | 2003-09-24 16:51:23 +0000 | [diff] [blame] | 143 | \index{GIL} |
Fred Drake | d4a1419 | 2003-09-27 18:59:43 +0000 | [diff] [blame] | 144 | \item[GIL] |
| 145 | See \emph{global interpreter lock}. |
Skip Montanaro | 757dedc | 2003-09-24 16:51:23 +0000 | [diff] [blame] | 146 | |
| 147 | \index{global interpreter lock} |
Fred Drake | d4a1419 | 2003-09-27 18:59:43 +0000 | [diff] [blame] | 148 | \item[global interpreter lock] |
| 149 | The lock used by Python threads to assure that only one thread can be |
| 150 | run at a time. This simplifies Python by assuring that no two |
| 151 | processes can access the same memory at the same time. Locking the |
| 152 | entire interpreter makes it easier for the interpreter to be |
Skip Montanaro | 757dedc | 2003-09-24 16:51:23 +0000 | [diff] [blame] | 153 | multi-threaded, at the expense of some parallelism on multi-processor |
Fred Drake | d4a1419 | 2003-09-27 18:59:43 +0000 | [diff] [blame] | 154 | machines. Efforts have been made in the past to create a |
Raymond Hettinger | 43b5e40 | 2003-09-27 20:19:02 +0000 | [diff] [blame] | 155 | ``free-threaded'' interpreter (one which locks shared data at a much |
Fred Drake | d4a1419 | 2003-09-27 18:59:43 +0000 | [diff] [blame] | 156 | finer granularity), but performance suffered in the common |
| 157 | single-processor case. |
Skip Montanaro | 757dedc | 2003-09-24 16:51:23 +0000 | [diff] [blame] | 158 | |
| 159 | \index{IDLE} |
Fred Drake | d4a1419 | 2003-09-27 18:59:43 +0000 | [diff] [blame] | 160 | \item[IDLE] |
| 161 | An Integrated Development Environment for Python. IDLE is a |
Raymond Hettinger | 5a25aa6 | 2003-09-27 05:42:14 +0000 | [diff] [blame] | 162 | basic editor and interpreter environment that ships with the standard |
| 163 | distribution of Python. Good for beginners, it also serves as clear |
| 164 | example code for those wanting to implement a moderately |
Fred Drake | d4a1419 | 2003-09-27 18:59:43 +0000 | [diff] [blame] | 165 | sophisticated, multi-platform GUI application. |
Skip Montanaro | 757dedc | 2003-09-24 16:51:23 +0000 | [diff] [blame] | 166 | |
| 167 | \index{immutable} |
Fred Drake | d4a1419 | 2003-09-27 18:59:43 +0000 | [diff] [blame] | 168 | \item[immutable] |
Skip Montanaro | dbb4078 | 2004-03-27 18:23:11 +0000 | [diff] [blame] | 169 | An object with fixed value. Immutable objects are numbers, strings or |
Fred Drake | d4a1419 | 2003-09-27 18:59:43 +0000 | [diff] [blame] | 170 | tuples (and more). Such an object cannot be altered. A new object |
Skip Montanaro | 757dedc | 2003-09-24 16:51:23 +0000 | [diff] [blame] | 171 | has to be created if a different value has to be stored. They play an |
Fred Drake | d4a1419 | 2003-09-27 18:59:43 +0000 | [diff] [blame] | 172 | important role in places where a constant hash value is needed. For |
| 173 | example as a key in a dictionary. |
Skip Montanaro | 757dedc | 2003-09-24 16:51:23 +0000 | [diff] [blame] | 174 | |
| 175 | \index{integer division} |
Fred Drake | d4a1419 | 2003-09-27 18:59:43 +0000 | [diff] [blame] | 176 | \item[integer division] |
| 177 | Mathematical division discarding any remainder. For example, the |
Raymond Hettinger | 43b5e40 | 2003-09-27 20:19:02 +0000 | [diff] [blame] | 178 | expression \code{11/4} currently evaluates to \code{2} in contrast |
Fred Drake | d4a1419 | 2003-09-27 18:59:43 +0000 | [diff] [blame] | 179 | to the \code{2.75} returned by float division. Also called |
| 180 | {}\emph{floor division}. When dividing two integers the outcome will |
| 181 | always be another integer (having the floor function applied to it). |
| 182 | However, if one of the operands is another numeric type (such as a |
| 183 | {}\class{float}), the result will be coerced (see \emph{coercion}) to |
Skip Montanaro | dbb4078 | 2004-03-27 18:23:11 +0000 | [diff] [blame] | 184 | a common type. For example, an integer divided by a float will result |
Fred Drake | d4a1419 | 2003-09-27 18:59:43 +0000 | [diff] [blame] | 185 | in a float value, possibly with a decimal fraction. Integer division |
| 186 | can be forced by using the \code{//} operator instead of the \code{/} |
| 187 | operator. See also \emph{__future__}. |
Skip Montanaro | 757dedc | 2003-09-24 16:51:23 +0000 | [diff] [blame] | 188 | |
| 189 | \index{interactive} |
Fred Drake | d4a1419 | 2003-09-27 18:59:43 +0000 | [diff] [blame] | 190 | \item[interactive] |
| 191 | Python has an interactive interpreter which means that you can try out |
| 192 | things and directly see its result. Just launch \code{python} with no |
| 193 | arguments (possibly by selecting it from your computer's main menu). |
| 194 | It is a very powerful way to test out new ideas or inspect modules and |
| 195 | packages (remember \code{help(x)}). |
Skip Montanaro | 757dedc | 2003-09-24 16:51:23 +0000 | [diff] [blame] | 196 | |
| 197 | \index{interpreted} |
Fred Drake | d4a1419 | 2003-09-27 18:59:43 +0000 | [diff] [blame] | 198 | \item[interpreted] |
Skip Montanaro | dbb4078 | 2004-03-27 18:23:11 +0000 | [diff] [blame] | 199 | Python is an interpreted language, as opposed to a compiled one. This means |
| 200 | that the source files can be run directly without first creating an |
| 201 | executable which is then run. Interpreted languages typically have a |
| 202 | shorter development/debug cycle than compiled ones, though their programs |
| 203 | generally also run more slowly. See also {}\emph{interactive}. |
Skip Montanaro | 757dedc | 2003-09-24 16:51:23 +0000 | [diff] [blame] | 204 | |
| 205 | \index{iterable} |
Fred Drake | d4a1419 | 2003-09-27 18:59:43 +0000 | [diff] [blame] | 206 | \item[iterable] |
| 207 | A container object capable of returning its members one at a time. |
Raymond Hettinger | 43b5e40 | 2003-09-27 20:19:02 +0000 | [diff] [blame] | 208 | Examples of iterables include all sequence types (such as \class{list}, |
Raymond Hettinger | 5a25aa6 | 2003-09-27 05:42:14 +0000 | [diff] [blame] | 209 | {}\class{str}, and \class{tuple}) and some non-sequence types like |
Fred Drake | d4a1419 | 2003-09-27 18:59:43 +0000 | [diff] [blame] | 210 | {}\class{dict} and \class{file} and objects of any classes you define |
| 211 | with an \method{__iter__()} or \method{__getitem__()} method. Iterables |
| 212 | can be used in a \keyword{for} loop and in many other places where a |
| 213 | sequence is needed (\function{zip()}, \function{map()}, ...). When an |
| 214 | iterable object is passed as an argument to the builtin function |
| 215 | {}\function{iter()}, it returns an iterator for the object. This |
| 216 | iterator is good for one pass over the set of values. When using |
| 217 | iterables, it is usually not necessary to call \function{iter()} or |
Raymond Hettinger | 43b5e40 | 2003-09-27 20:19:02 +0000 | [diff] [blame] | 218 | deal with iterator objects yourself. The \code{for} statement does |
Fred Drake | d4a1419 | 2003-09-27 18:59:43 +0000 | [diff] [blame] | 219 | that automatically for you, creating a temporary unnamed variable to |
| 220 | hold the iterator for the duration of the loop. See also |
| 221 | {}\emph{iterator}, \emph{sequence}, and \emph{generator}. |
Skip Montanaro | 757dedc | 2003-09-24 16:51:23 +0000 | [diff] [blame] | 222 | |
| 223 | \index{iterator} |
Fred Drake | d4a1419 | 2003-09-27 18:59:43 +0000 | [diff] [blame] | 224 | \item[iterator] |
| 225 | An object representing a stream of data. Repeated calls to the |
| 226 | iterator's \method{next()} method return successive items in the |
Skip Montanaro | 757dedc | 2003-09-24 16:51:23 +0000 | [diff] [blame] | 227 | stream. When no more data is available a \exception{StopIteration} |
Fred Drake | d4a1419 | 2003-09-27 18:59:43 +0000 | [diff] [blame] | 228 | exception is raised instead. At this point, the iterator object is |
| 229 | exhausted and any further calls to its \method{next()} method just |
| 230 | raise \exception{StopIteration} again. Iterators are required to have |
| 231 | an \method{__iter__()} method that returns the iterator object |
| 232 | itself so every iterator is also iterable and may be used in most |
| 233 | places where other iterables are accepted. One notable exception is |
| 234 | code that attempts multiple iteration passes. A container object |
| 235 | (such as a \class{list}) produces a fresh new iterator each time you |
| 236 | pass it to the \function{iter()} function or use it in a |
| 237 | {}\keyword{for} loop. Attempting this with an iterator will just |
| 238 | return the same exhausted iterator object from the second iteration |
| 239 | pass, making it appear like an empty container. |
Skip Montanaro | 757dedc | 2003-09-24 16:51:23 +0000 | [diff] [blame] | 240 | |
| 241 | \index{list comprehension} |
Fred Drake | d4a1419 | 2003-09-27 18:59:43 +0000 | [diff] [blame] | 242 | \item[list comprehension] |
| 243 | A compact way to process all or a subset of elements in a sequence and |
| 244 | return a list with the results. \code{result = ["0x\%02x" |
Skip Montanaro | 757dedc | 2003-09-24 16:51:23 +0000 | [diff] [blame] | 245 | \% x for x in range(256) if x \% 2 == 0]} generates a list of strings |
| 246 | containing hex numbers (0x..) that are even and in the range from 0 to 255. |
| 247 | The \keyword{if} clause is optional. If omitted, all elements in |
Fred Drake | d4a1419 | 2003-09-27 18:59:43 +0000 | [diff] [blame] | 248 | {}\code{range(256)} are processed in that case. |
Skip Montanaro | 757dedc | 2003-09-24 16:51:23 +0000 | [diff] [blame] | 249 | |
| 250 | \index{mapping} |
Fred Drake | d4a1419 | 2003-09-27 18:59:43 +0000 | [diff] [blame] | 251 | \item[mapping] |
| 252 | A container object (such as \class{dict}) that supports arbitrary key |
| 253 | lookups using the special method \method{__getitem__()}. |
Skip Montanaro | 757dedc | 2003-09-24 16:51:23 +0000 | [diff] [blame] | 254 | |
| 255 | \index{metaclass} |
Fred Drake | d4a1419 | 2003-09-27 18:59:43 +0000 | [diff] [blame] | 256 | \item[metaclass] |
| 257 | The class of a class. Class definitions create a class name, a class |
| 258 | dictionary, and a list of base classes. The metaclass is responsible |
| 259 | for taking those three arguments and creating the class. Most object |
| 260 | oriented programming languages provide a default implementation. What |
| 261 | makes Python special is that it is possible to create custom |
| 262 | metaclasses. Most users never need this tool, but when the need |
| 263 | arises, metaclasses can provide powerful, elegant solutions. They |
| 264 | have been used for logging attribute access, adding thread-safety, |
| 265 | tracking object creation, implementing singletons, and many other |
| 266 | tasks. |
Skip Montanaro | 757dedc | 2003-09-24 16:51:23 +0000 | [diff] [blame] | 267 | |
| 268 | \index{LBYL} |
Fred Drake | d4a1419 | 2003-09-27 18:59:43 +0000 | [diff] [blame] | 269 | \item[LBYL] |
| 270 | Look before you leap. This coding style explicitly tests for |
| 271 | pre-conditions before making calls or lookups. This style contrasts |
| 272 | with the \emph{EAFP} approach and is characterized the presence of |
| 273 | many \keyword{if} statements. |
Skip Montanaro | 757dedc | 2003-09-24 16:51:23 +0000 | [diff] [blame] | 274 | |
| 275 | \index{mutable} |
Fred Drake | d4a1419 | 2003-09-27 18:59:43 +0000 | [diff] [blame] | 276 | \item[mutable] |
| 277 | Mutable objects can change their value but keep their \function{id()}. |
| 278 | See also \emph{immutable}. |
Skip Montanaro | 757dedc | 2003-09-24 16:51:23 +0000 | [diff] [blame] | 279 | |
| 280 | \index{namespace} |
Fred Drake | d4a1419 | 2003-09-27 18:59:43 +0000 | [diff] [blame] | 281 | \item[namespace] |
| 282 | The place where a variable is stored. Namespaces are implemented as |
| 283 | dictionary. There is the local, global and builtins namespace and the |
| 284 | nested namespaces in objects (in methods). Namespaces support |
| 285 | modularity by preventing naming conflicts. For instance, the |
| 286 | functions \function{__builtin__.open()} and \function{os.open()} are |
| 287 | distinguished by their namespaces. Namespaces also aid readability |
| 288 | and maintainability by making it clear which modules implement a |
| 289 | function. For instance, writing \function{random.seed()} or |
| 290 | {}\function{itertools.izip()} makes it clear that those functions are |
Fred Drake | 984920b | 2003-09-28 19:03:36 +0000 | [diff] [blame] | 291 | implemented by the \ulink{\module{random}}{../lib/module-random.html} |
| 292 | and \ulink{\module{itertools}}{../lib/module-itertools.html} modules |
| 293 | respectively. |
Skip Montanaro | 757dedc | 2003-09-24 16:51:23 +0000 | [diff] [blame] | 294 | |
| 295 | \index{nested scope} |
Fred Drake | d4a1419 | 2003-09-27 18:59:43 +0000 | [diff] [blame] | 296 | \item[nested scope] |
| 297 | The ability to refer to a variable in an enclosing definition. For |
| 298 | instance, a function defined inside another function can refer to |
| 299 | variables in the outer function. Note that nested scopes work only |
Skip Montanaro | 757dedc | 2003-09-24 16:51:23 +0000 | [diff] [blame] | 300 | for reference and not for assignment which will always write to the |
Fred Drake | d4a1419 | 2003-09-27 18:59:43 +0000 | [diff] [blame] | 301 | innermost scope. In contrast, local variables both read and write in |
| 302 | the innermost scope. Likewise, global variables read and write to the |
| 303 | global namespace. |
Skip Montanaro | 757dedc | 2003-09-24 16:51:23 +0000 | [diff] [blame] | 304 | |
| 305 | \index{new-style class} |
Fred Drake | d4a1419 | 2003-09-27 18:59:43 +0000 | [diff] [blame] | 306 | \item[new-style class] |
| 307 | Any class that inherits from \class{object}. This includes all |
| 308 | built-in types like \class{list} and \class{dict}. Only new-style |
| 309 | classes can use Python's newer, versatile features like |
Raymond Hettinger | 43b5e40 | 2003-09-27 20:19:02 +0000 | [diff] [blame] | 310 | {}\method{__slots__}, descriptors, properties, |
Fred Drake | d4a1419 | 2003-09-27 18:59:43 +0000 | [diff] [blame] | 311 | \method{__getattribute__()}, class methods, and static methods. |
Skip Montanaro | 757dedc | 2003-09-24 16:51:23 +0000 | [diff] [blame] | 312 | |
| 313 | \index{Python3000} |
Fred Drake | d4a1419 | 2003-09-27 18:59:43 +0000 | [diff] [blame] | 314 | \item[Python3000] |
| 315 | A mythical python release, allowed not to be backward compatible, with |
| 316 | telepathic interface. |
Skip Montanaro | 757dedc | 2003-09-24 16:51:23 +0000 | [diff] [blame] | 317 | |
Raymond Hettinger | 43b5e40 | 2003-09-27 20:19:02 +0000 | [diff] [blame] | 318 | \index{__slots__} |
| 319 | \item[__slots__] |
| 320 | A declaration inside a \emph{new-style class} that saves memory by |
| 321 | pre-declaring space for instance attributes and eliminating instance |
| 322 | dictionaries. Though popular, the technique is somewhat tricky to get |
| 323 | right and is best reserved for rare cases where there are large |
| 324 | numbers of instances in a memory critical application. |
| 325 | |
Skip Montanaro | 757dedc | 2003-09-24 16:51:23 +0000 | [diff] [blame] | 326 | \index{sequence} |
Fred Drake | d4a1419 | 2003-09-27 18:59:43 +0000 | [diff] [blame] | 327 | \item[sequence] |
| 328 | An \emph{iterable} which supports efficient element access using |
| 329 | integer indices via the \method{__getitem__()} and |
| 330 | {}\method{__len__()} special methods. Some built-in sequence types |
| 331 | are \class{list}, \class{str}, \class{tuple}, and \class{unicode}. |
| 332 | Note that \class{dict} also supports \method{__getitem__()} and |
| 333 | {}\method{__len__()}, but is considered a mapping rather than a |
| 334 | sequence because the lookups use arbitrary \emph{immutable} keys |
| 335 | rather than integers. |
Skip Montanaro | 757dedc | 2003-09-24 16:51:23 +0000 | [diff] [blame] | 336 | |
| 337 | \index{Zen of Python} |
Fred Drake | d4a1419 | 2003-09-27 18:59:43 +0000 | [diff] [blame] | 338 | \item[Zen of Python] |
| 339 | Listing of Python design principles and philosophies that are helpful |
| 340 | in understanding and using the language. The listing can be found by |
Raymond Hettinger | 43b5e40 | 2003-09-27 20:19:02 +0000 | [diff] [blame] | 341 | typing ``\code{import this}'' at the interactive prompt. |
Skip Montanaro | 757dedc | 2003-09-24 16:51:23 +0000 | [diff] [blame] | 342 | |
| 343 | \end{description} |