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