This page intentionally left blank Python for Software Design



tải về 1.38 Mb.
Chế độ xem pdf
trang82/83
Chuyển đổi dữ liệu13.08.2023
Kích1.38 Mb.
#55046
1   ...   75   76   77   78   79   80   81   82   83
- Python for Software Design How to Think Like a Computer Scientist-Cambridge University Press (2009)

x
2
π
into Python, you might write:
y = x / 2 * math.pi
That is not correct because multiplication and division have the same precedence
and are evaluated from left to right. So this expression computes x
π/2.
A good way to debug expressions is to add parentheses to make the order of
evaluation explicit:
y = x / (2 * math.pi)
Whenever you are not sure of the order of evaluation, use parentheses. Not only
will the program be correct (in the sense of doing what you intended), it will also be
more readable for other people who haven’t memorized the rules of precedence.


238
Debugging
A.3.3
I’ve Got a Function or Method That Doesn’t Return What I Expect
If you have a return statement with a complex expression, you don’t have a chance
to print the return value before returning. Again, you can use a temporary variable.
For example, instead of:
return self.hands[i].removeMatches()
you could write:
count = self.hands[i].removeMatches()
return count
Now you have the opportunity to display the value of count before returning.
A.3.4
I’m Really, Really Stuck and I Need Help
First, try getting away from the computer for a few minutes. Computers emit waves
that affect the brain, causing these symptoms:

Frustration and rage.

Superstitious beliefs (“the computer hates me”) and magical thinking (“the
program only works when I wear my hat backward”).

Random walk programming (the attempt to program by writing every possible
program and choosing the one that does the right thing).
If you find yourself suffering from any of these symptoms, get up and go for a walk.
When you are calm, think about the program. What is it doing? What are some
possible causes of that behavior? When was the last time you had a working program,
and what did you do next?
Sometimes it just takes time to find a bug. I often find bugs when I am away from the
computer and let my mind wander. Some of the best places to find bugs are trains,
showers, and in bed, just before you fall asleep.
A.3.5
No, I Really Need Help
It happens. Even the best programmers occasionally get stuck. Sometimes you work
on a program so long that you can’t see the error. A fresh pair of eyes is just the
thing.
Before you bring someone else in, make sure you are prepared. Your program
should be as simple as possible, and you should be working on the smallest input
that causes the error. You should have print statements in the appropriate places
(and the output they produce should be comprehensible). You should understand
the problem well enough to describe it concisely.


A.3 Semantic Errors
239
When you bring someone in to help, be sure to give them the information they need:

If there is an error message, what is it and what part of the program does it
indicate?

What was the last thing you did before this error occurred? What were the last
lines of code that you wrote, or what is the new test case that fails?

What have you tried so far, and what have you learned?
When you find the bug, take a second to think about what you could have done to
find it faster. Next time you see something similar, you will be able to find the bug
more quickly.
Remember, the goal is not just to make the program work. The goal is to learn how
to make the program work.



Index
abecedarian, 84, 97
abs function, 60
absolute path, 162, 169
access, 104
accumulator, 116
histogram, 150
list, 109
string, 205
sum, 108
Ackerman function, 71
add method, 195
addition with carrying, 79
algorithm, 3, 8, 79, 154
Euclid, 72
MD5, 170
RSA, 130
square root, 80
aliasing, 112, 113, 116, 174, 177, 200
copying to avoid, 116
alphabet, 45
alternative execution, 48
ambiguity, 6
anagram, 117
anagram set, 145, 166
and operator, 47
anydbm module, 164
append method, 107, 114, 118, 205, 206
arc function, 38
argument, 21, 24, 27, 28, 32, 113
gather, 136
keyword, 40, 44, 142, 215
list, 113
optional, 88, 111, 124
variable-length tuple, 136
argument scatter, 137
arithmetic operator, 14
assert statement, 187
assignment, 18, 73, 104
item, 86, 104, 134
multiple, 80, 128
tuple, 135, 136, 138, 144
assignment statement, 11
attribute
__dict__, 198
class, 202, 211
initializing, 198
instance, 173, 179, 203, 211
AttributeError, 179, 235
Austen, Jane, 150
available colors, 181, 200
Bacon, Kevin, 171
Bangladesh, national flag, 180
base case, 52, 55
benchmarking, 156, 158
big, hairy expression, 237
binding, 223, 227
bingo, 145
birthday, 188
birthday paradox, 117
bisect module, 118
bisection search, 118
bisection, debugging by, 79
bitwise operator, 14
body, 24, 32, 55, 75
bool type, 47
boolean expression, 46, 55
boolean function, 64, 183
241


242
Index
boolean operator, 89
borrowing, subtraction with, 79, 186
bound method, 221, 227
bounding box, 180, 218, 227
bracket
squiggly, 119
bracket operator, 82, 104, 134
branch, 49, 55
break statement, 76
bug, 3, 8
worst, 199
worst ever, 229
Button widget, 215
calculator, 9, 20
call graph, 127, 131
Callable object, 223
callback, 216, 221, 223, 226, 227
Canvas coordinate, 217, 226
Canvas item, 217
Canvas object, 180
Canvas widget, 216
Car Talk, 101, 102, 132, 145
Card class, 202
card, playing, 201
carrying, addition with, 79, 184, 185
case-sensitivity, variable names, 18
catch, 169
chained conditional, 49, 55
character, 82
checksum, 170
child class, 207, 211
choice function, 149
circle function, 38
circular definition, 65
class, 172, 179
Card, 202
child, 207, 211
Date, 188
Deck, 205
Hand, 207
Kangaroo, 199
parent, 207
Point, 172, 194
Rectangle, 175
SimpleTurtleWorld, 220
Time, 182
class attribute, 202, 211
class definition, 172
class diagram, 209, 211
class object, 173, 179
close method, 160, 165, 166
cmp function, 205
__cmp__ method, 204
Collatz conjecture, 76
colon, 24, 232
color list, 181, 200
comment, 17, 18
commutativity, 16, 196
compare function, 60
comparison
string, 89
tuple, 141, 204
comparison operator, 47
compile, 2, 8
composition, 23, 28, 32, 63, 205
compound statement, 48, 55
compression
file, 166
concatenation, 16, 18, 28, 84, 86, 111
list, 106, 114, 118
condition, 48, 55, 75, 233
conditional, 232
chained, 49, 55
nested, 49, 56
conditional execution, 48
conditional operator, 204
conditional statement, 48, 56, 64
config method, 216
consistency check, 130, 186
conversion
type, 21
coordinate
Canvas, 217, 226
pixel, 226
coordinate sequence, 217
copy
deep, 178
shallow, 178
slice, 86, 106
to avoid aliasing, 116
copy module, 177
copying objects, 177
count method, 89
counter, 87, 92, 121, 129
counting and looping, 87
crosswords, 95
cummings, e. e., 3
cumulative sum, 109
Czech Republic, national flag, 181
data structure, 143, 144, 155
database, 164, 169, 170
Date class, 188


Index
243
datetime module, 188
dead code, 60, 70, 236
debugger (pdb), 235
debugging, 3, 7, 8, 17, 31, 43, 54, 69, 90, 100,
115, 130, 143, 157, 168, 179, 187, 198,
210, 226, 231
by bisection, 79
emotional response, 7, 238
experimental, 4
superstition, 238
Deck class, 205
deck, playing cards, 205
declaration, 128, 131
decorate-sort-undecorate pattern, 142
decrement, 75, 80
deep copy, 178, 179
deepcopy function, 178
def keyword, 24
default value, 152, 158, 193
avoiding mutable, 199
definition
circular, 65
class, 172
function, 24
recursive, 146
del operator, 110
deletion, element of list, 109
delimiter, 111, 116
deterministic, 148, 158
development plan, 44
encapsulation and generalization, 42
incremental, 60, 231
planned, 185
problem recognition, 99, 100
prototype and patch, 183, 185
random walk programming, 157, 238
diagram
call graph, 131
class, 209, 211
object, 173, 175, 178, 179, 182, 203
stack, 29, 114
state, 11, 73, 92, 104, 112, 113, 125, 141,
173, 175, 178, 182, 203
__dict__ attribute, 198
dict function, 119
dictionary, 119, 131, 139, 235
initialize, 139
invert, 125
lookup, 123
looping with, 123
reverse lookup, 123
subtraction, 152
traversal, 140, 199
dictionary methods
anydbm module, 164
Dijkstra, Edsger, 101
directory, 161, 169
walk, 162
working, 162
dispatch
type-based, 197
dispatch, type-based, 196
divisibility, 46
division
floating-point, 14
floor, 14, 55
divmod, 136, 186
docstring, 43, 44, 172
documentation, 9
dot notation, 23, 32, 87, 173, 191, 203
double letters, 101
Doyle, Arthur Conan, 4
drag-and-drop, 225
DSU pattern, 142, 144, 151
duplicate, 117, 118, 131, 170
Einstein, Albert, 40
element, 103, 116
element deletion, 109
elif keyword, 49
ellipses, 24
else keyword, 48
email address, 135
embedded object, 175, 179, 200
copying, 178
emotional debugging, 7, 238
empty list, 103
empty string, 92, 111
encapsulation, 39, 44, 63, 79, 87, 208
encode, 201, 211
encrypt, 201
encryption, 130
end of line character, 169
Entry widget, 218
enumerate function, 139
epsilon, 78
equality and assignment, 73
equivalence, 112
equivalent, 116
error
compile-time, 231
runtime, 4, 18, 52, 55, 231
semantic, 4, 11, 18, 91, 231, 236
shape, 143
syntax, 3, 17, 231


244
Index
error checking, 68
error message, 3, 4, 7, 11, 18, 231
Euclid’s algorithm, 72
eval function, 81
evaluate, 15
event, 227
event handler, 224
event loop, 215, 227
Event object, 224
event string, 224
event-driven programming, 216, 226, 227
exception, 4, 8, 18, 231, 234
AttributeError, 179, 235
IndexError, 83, 91, 105, 235
IOError, 163
KeyError, 120, 235
NameError, 29, 235
OverflowError, 55
RuntimeError, 52
SyntaxError, 24
TypeError, 83, 86, 126, 134, 137, 161, 192,
235
UnboundLocalError, 129
ValueError, 54, 124, 135
exception, catching, 163
executable, 2, 8
exercise, secret, 169
exists function, 162
experimental debugging, 4, 157
expression, 14, 15, 18
big and hairy, 237
boolean, 46, 55
extend method, 107
factorial function, 65, 68
False special value, 47
Fermat’s Last Theorem, 56
fibonacci function, 67, 126
file, 159
compression, 166
permission, 163
reading and writing, 159
file object, 95, 101
filename, 161
filter pattern, 109, 117
find function, 86
flag, 128, 131
float function, 22
float type, 10
floating-point, 18, 78
floating-point division, 14
floor division, 14, 19, 55
flow of execution, 26, 32, 68, 69, 75, 210,
226, 234
flower, 45
folder, 161
for loop, 37, 83, 105, 139
formal language, 5, 8
format operator, 160, 169, 235
format sequence, 160, 169
format string, 160, 169
frabjous, 65
frame, 29, 32, 52, 66, 127
Frame widget, 220
frequency, 122
letter, 145
word, 147, 158
fruitful function, 30, 32
frustration, 238
function, 24, 32, 189
abs, 60
ack, 71
arc, 38
choice, 149
circle, 38
cmp, 205
compare, 60
deepcopy, 178
dict, 119
enumerate, 139
eval, 81
exists, 162
factorial, 65
fibonacci, 67, 126
find, 86
float, 22
getattr, 199
getcwd, 161
hasattr, 179, 198
int, 21
isinstance, 68, 196
len, 33, 83, 120
list, 110
log, 23
max, 136, 137
min, 136, 137
open, 95, 96, 159, 163, 164
polygon, 38
popen, 166
randint, 117, 148
random, 142, 148
raw_input, 53
recursive, 51
reload, 168, 232
repr, 168


Index
245
reversed, 143
shuffle, 207
sorted, 143
sqrt, 23, 62
str, 22
sum, 137
tuple, 134
type, 179
zip, 138
function argument, 27
function call, 21, 32
function composition, 63
function definition, 24, 26, 32
function frame, 29, 32, 52, 127
function object, 25, 33
function parameter, 27
function syntax, 191
function type
modifier, 184
pure, 183
function, fruitful, 30
function, math, 22
function, reasons for, 31
function, trigonometric, 23
function, tuple as return value, 136
function, void, 30
functional programming style, 185, 188
gamma function, 68
gather, 136, 144
GCD (greatest common divisor), 72
generalization, 39, 44, 97, 186
geometry manager, 222, 227
get method, 122
getattr function, 199
getcwd function, 161
global statement, 128
global variable, 128, 131
update, 128
GNU Free Documentation License, vi, vii
graphical user interface, 214
greatest common divisor (GCD), 72
grid, 34
guardian pattern, 69, 70, 90
GUI, 214, 227
Gui module, 214
gunzip (Unix command), 166
Hand class, 207
hanging, 233
HAS-A relationship, 209, 211
hasattr function, 179, 198
hash function, 126, 131
hashable, 126, 131, 140
hashtable, 121, 131
header, 24, 32, 232
Hello, World, 6
help utility, 9
hexadecimal, 173
high-level language, 1, 8
histogram, 122, 131
random choice, 149, 153
word frequencies, 149
Holmes, Sherlock, 4
homophone, 132
HTMLParser module, 229
hyperlink, 229
hypotenuse, 63
identical, 117
identity, 112
if statement, 48
Image module, 228
image viewer, 228
IMDb (Internet Movie Database), 170
immutability, 86, 92, 113, 126, 133, 142
implementation, 121, 131, 155
import statement, 32, 35, 168
in operator, 89, 97, 105, 120
increment, 75, 80, 184, 192
incremental development, 70, 231
indentation, 24, 190, 232
index, 82, 83, 90, 92, 104, 117, 119, 235
looping with, 99, 105
negative, 83
slice, 85, 106
starting at zero, 83, 104
IndexError, 83, 91, 105, 235
infinite loop, 75, 80, 215, 233
infinite recursion, 52, 56, 68, 233, 234
inheritance, 207, 211
init method, 193, 198, 202, 205, 208
initialization (before update), 74
instance, 36, 44, 173, 179
as argument, 174
as return value, 176
instance attribute, 173, 179, 203, 211
instantiation, 173
int function, 21
int type, 10
integer, 19
long, 129
interactive mode, 2, 8, 13, 31
interface, 40, 43, 44, 211


246
Index
interlocking words, 118
Internet Movie Database (IMDb), 170
interpret, 2, 8
invariant, 187, 188, 227
invert dictionary, 125
invocation, 88, 92
IOError, 163
is operator, 112, 178
IS-A relationship, 209, 211
isinstance function, 68, 196
item, 92, 103
Canvas, 217, 227
dictionary, 131
item assignment, 86, 104, 134
item update, 105
items method, 139
iteration, 73, 75, 80
join method, 111, 205
Kangaroo class, 199
Kevin Bacon Game, 171
key, 119, 131
key-value pair, 119, 131, 139
keyboard input, 53
KeyError, 120, 235
keys method, 123
keyword, 13, 19, 232
def, 24
elif, 49
else, 48
keyword argument, 40, 44, 142, 215, 227
Koch curve, 57
Label widget, 215
language
formal, 5
high-level, 1
low-level, 1
natural, 5
programming, 1
safe, 4
Turing complete, 65
leap of faith, 67
len function, 33, 83, 120
letter frequency, 145
letter rotation, 94, 132
Linux, 5
lipogram, 97
list, 103, 110, 117, 142
as argument, 113
comprehension, 109
concatenation, 106, 114, 118
copy, 106
element, 104
empty, 103
function, 110
index, 105
membership, 105
method, 107
nested, 103, 106
of objects, 205
of tuples, 138
operation, 106
repetition, 106
slice, 106
traversal, 105, 117
literalness, 6
local variable, 28, 32
log function, 23
logarithm, 158
logical operator, 46, 47
long integer, 129
lookup, 131
lookup, dictionary, 123
loop, 37, 44, 75, 138
condition, 233
event, 215
for, 37, 83, 105
infinite, 75, 215, 233
nested, 205
traversal, 83
while, 75
looping
with dictionaries, 123
with indices, 99
with strings, 87
looping and counting, 87
looping with indices, 105
low-level language, 1, 8
ls (Unix command), 166
map pattern, 109, 117
map to, 201
mapping, 104, 117, 154
Markov analysis, 154
mash-up, 155
math function, 22
max function, 136, 137
McCloskey, Robert, 84
MD5 algorithm, 170
membership
bisection search, 118
dictionary, 120


Index
247
list, 105
set, 121
memo, 127, 131
mental model, 236
Menubutton widget, 223
metaphor, method invocation, 191
metathesis, 145
method, 87, 92, 189, 199
__cmp__, 204
__str__, 194, 205
add, 195
append, 107, 114, 205, 206
close, 160, 165, 166
config, 216
count, 89
extend, 107
get, 122
init, 193, 202, 205, 208
items, 139
join, 111, 205
keys, 123
mro, 211
pop, 109, 206
radd, 197
read, 166
readline, 95, 166
remove, 110
replace, 147
setdefault, 126
sort, 107, 115, 141, 207
split, 111, 135
string, 93
strip, 96, 147
translate, 147
update, 140
values, 121
void, 107
method append, 118
method resolution order, 211
method syntax, 191
method, bound, 221
method, list, 107
min function, 136, 137
model, mental, 236
modifier, 184, 188
module, 22, 32
anydbm, 164
bisect, 118
copy, 177
datetime, 188
Gui, 214
HTMLParser, 229
Image, 228
os, 161
pickle, 159, 165
pprint, 131
profile, 156
random, 117, 142, 148, 207
reload, 168, 232
shelve, 166, 170
string, 147
structshape, 143
urllib, 169, 229
Visual, 200
vpython, 200
World, 180
module object, 22, 167
module, writing, 167
modulus operator, 46, 56
Monty Python and the Holy Grail, 183
MP3, 170
mro method, 211
multiline string, 43, 232
multiple assignment, 73, 80, 128
multiplicity (in class diagram), 210, 211
mutability, 86, 104, 107, 113, 129, 133, 142,
176
mutable object, as default value, 199
NameError, 29, 235
natural language, 5, 8
negative index, 83
nested conditional, 49, 56
nested list, 103, 106, 117
newline, 53, 73, 205
Newton’s method, 77
None special value, 31, 60, 71, 107, 110
not operator, 47
number, random, 148
object, 86, 92, 111, 112, 117, 172
Callable, 223
Canvas, 180
class, 173
copying, 177
embedded, 175, 179, 200
Event, 224
file, 95, 101
function, 25, 33
module, 167
mutable, 176
printing, 190
object code, 2, 8
object diagram, 173, 175, 178, 179, 182, 203
object-oriented language, 199


248
Index
object-oriented programming, 189, 199, 207
octal, 12
odometer, 101
open function, 95, 96, 159, 163, 164
operand, 14, 19
operator, 19
and, 47
bitwise, 14
boolean, 89
bracket, 82, 104, 134
comparison, 47
conditional, 204
del, 110
format, 160, 169, 235
in, 89, 97, 105, 120
is, 112, 178
logical, 46, 47
modulus, 46, 56
not, 47
or, 47
overloading, 199
slice, 85, 92, 106, 115, 134
string, 16
update, 108
operator overloading, 195, 204
operator, arithmetic, 14
option, 215, 228
optional argument, 88, 111, 124
optional parameter, 152, 193
or operator, 47
order of operations, 15, 18, 237
os module, 161
other (parameter name), 193
OverflowError, 55
overloading, 199
override, 152, 158, 193, 204, 208, 211
packing widgets, 220, 228
palindrome, 72, 93, 100–102
parameter, 27, 29, 32, 113
gather, 136
optional, 152, 193
other, 193
self, 191
parent class, 207, 211
parentheses
argument in, 21
empty, 24, 88
matching, 3
overriding precedence, 16
parameters in, 27, 28
parent class in, 207
tuples in, 133
parse, 5, 8, 170
pass statement, 48
path, 161, 169
absolute, 162
relative, 162
pattern
decorate-sort-undecorate, 142
DSU, 142, 151
filter, 109, 117
guardian, 69, 70, 90
map, 109, 117
reduce, 108, 117
search, 87, 92, 97, 124
swap, 135
pdb (Python debugger), 235
PEMDAS, 15
permission, file, 163
persistence, 159, 169
pi, 23, 81
pickle module, 159, 165
pickling, 165
pie, 45
PIL (Python Imaging Library), 228
pipe, 166, 170
pixel coordinate, 226
plain text, 95, 147, 170, 229
planned development, 185, 188
playing card, Anglo-American, 201
poetry, 6
Point class, 172, 194
point, mathematical, 172
poker, 201, 212
polygon function, 38
polymorphism, 198, 199, 210
pop method, 109, 206
popen function, 166
portability, 1, 8
postcondition, 43, 69, 211
pprint module, 131
precedence, 19, 237
precondition, 43, 44, 69, 117, 211
prefix, 154
pretty print, 131
print statement, 7, 8, 194, 235
problem recognition, 99–101
problem solving, 1, 8
profile module, 156
program, 3, 8
program testing, 100
programming language, 1
Project Gutenberg, 147


Index
249
prompt, 2, 8, 53
prose, 6
prototype and patch, 183, 185, 188
pseudorandom, 148, 158
pure function, 183, 188
Puzzler, 101, 102, 132, 145
Pythagorean theorem, 61
Python 3.0, 7, 14, 53, 130, 138
Python debugger (pdb), 235
Python Imaging Library (PIL), 228
python.org, 9
quotation mark, 7, 10, 11, 43, 85, 232
radd method, 197
radian, 23
rage, 238
raise statement, 124, 187
Ramanujan, Srinivasa, 81
randint function, 117, 148
random function, 142, 148
random module, 117, 142, 148, 207
random number, 148
random text, 155
random walk programming, 157, 238
rank, 201
raw_input function, 53
read method, 166
readline method, 95, 166
Rectangle class, 175
recursion, 50, 51, 56, 65, 67
base case, 52
infinite, 52, 68, 234
recursive definition, 65, 146
reduce pattern, 108, 117
reducible word, 132, 146
redundancy, 6
refactoring, 41, 42
reference, 113, 117
aliasing, 113
relative path, 162, 169
reload function, 168, 232
remove method, 110
repetition, 36
list, 106
replace method, 147
repr function, 168
representation, 172, 175, 201
return statement, 51, 59, 238
return value, 21, 33, 59, 176
tuple, 136
reverse lookup, dictionary, 123, 131
reverse word pair, 118
reversed function, 143
rotation
letters, 132
rotation, letter, 94
RSA algorithm, 130
rules of precedence, 15, 19
running pace, 9, 20, 188
runtime error, 4, 18, 52, 55, 231, 234
RuntimeError, 52, 68
safe language, 4
sanity check, 130
scaffolding, 62, 71, 131
scatter, 137, 144
Scrabble, 145
script, 2, 8
script mode, 2, 9, 13, 31
search, 124
search pattern, 87, 92, 97
search, bisection, 118
secret exercise, 169
self (parameter name), 191
semantic error, 4, 9, 11, 18, 91, 231, 236
semantics, 4, 9, 189
sequence, 82, 92, 103, 110, 133, 142
coordinate, 217
set, 153
anagram, 145, 166
set membership, 121
setdefault method, 126
sexagesimal, 185
shallow copy, 178, 179
shape, 144
shape error, 143
shell, 166
shelve module, 166, 170
shuffle function, 207
SimpleTurtleWorld class, 220
sine function, 23
singleton, 125, 131, 133
slice, 92
copy, 86, 106
list, 106
string, 85
tuple, 134
update, 107
slice operator, 85, 92, 106, 115, 134
sort method, 107, 115, 141, 207
sorted function, 143
source code, 2, 9
special case, 101, 185


250
Index
special value
False, 47
None, 31, 60, 71, 107, 110
True, 47
split method, 111, 135
sqrt, 62
sqrt function, 23
square root, 77
squiggly bracket, 119
stack diagram, 29, 33, 44, 52, 66, 71, 114
state diagram, 11, 19, 73, 92, 104, 112, 113,
125, 141, 173, 175, 178, 182, 203
statement, 13, 19
assert, 187
assignment, 11, 73
break, 76
compound, 48
conditional, 48, 56, 64
for, 37, 83, 105
global, 128
if, 48
import, 32, 35, 168
pass, 48
print, 7, 8, 194, 235
raise, 124, 187
return, 51, 59, 238
try, 163
while, 75
step size, 92
str function, 22
__str__ method, 194, 205
string, 10, 19, 110, 142
accumulator, 205
comparison, 89
empty, 111
immutable, 86
method, 87
multiline, 43, 232
operation, 16
slice, 85
triple-quoted, 43
string method, 93
string module, 147
string representation, 168, 194
string type, 10
strip method, 96, 147
structshape module, 143
structure, 5
subclass, 207
subject, 191, 199, 221
subtraction
dictionary, 152
with borrowing, 79
subtraction with borrowing, 186
suffix, 154
suit, 201
sum function, 137
superclass, 207
superstitious debugging, 238
SVG, 229
Swampy, 35, 95, 180, 212, 214
swap pattern, 135
syntax, 3, 9, 189, 232
syntax error, 3, 9, 17, 231
SyntaxError, 24
Tagger, 213
temporary variable, 60, 71, 237
test case, minimal, 236
testing
and absence of bugs, 101
incremental development, 61
interactive mode, 2
is hard, 100
knowing the answer, 61
leap of faith, 67
minimal test case, 236
text
plain, 95, 147, 170, 229
random, 155
text file, 169
Text widget, 218
Time class, 182
Tkinter, 214
token, 5, 9
traceback, 30, 33, 52, 54, 124, 234
translate method, 147
traversal, 83, 87, 90, 92, 97, 98, 108, 117, 122,
123, 138, 139, 142, 150
dictionary, 199
list, 105
traverse
dictionary, 140
triangle, 56
trigonometric function, 23
triple-quoted string, 43
True special value, 47
try statement, 163
tuple, 133, 136, 142, 144
as key in dictionary, 140, 156
assignment, 135
comparison, 141, 204
in brackets, 140
singleton, 133
slice, 134


Index
251
tuple assignment, 136, 138, 144
tuple function, 134
Turing complete language, 65
Turing Thesis, 65
Turing, Alan, 65
turtle typewriter, 45
TurtleWorld, 35, 57, 212
type, 10, 19
bool, 47
dict, 119
file, 159
float, 10
int, 10
list, 103
long, 129
set, 153
str, 10
tuple, 133
user-defined, 172, 182
type checking, 68
type conversion, 21
type function, 179
type-based dispatch, 196, 197, 199
TypeError, 83, 86, 126, 134, 137, 161, 192,
235
typewriter, turtle, 45
typographical error, 157
UML, 209
UnboundLocalError, 129
underscore character, 13
uniqueness, 118
Unix command
gunzip, 166
ls, 166
update, 74, 78, 80
coordinate, 225
database, 164
global variable, 128
histogram, 150
item, 105
slice, 107
update method, 140
update operator, 108
URL, 169, 229
urllib module, 169, 229
use before def, 18, 26
user-defined type, 172, 182
value, 10, 19, 111, 112, 131
default, 152
tuple, 136
ValueError, 54, 124, 135
values method, 121
variable, 11, 19
global, 128
local, 28
temporary, 60, 71, 237
updating, 74
variable-length argument tuple, 136
vector graphics, 229
veneer, 206, 211
Visual module, 200
void function, 30, 33
void method, 107
vpython module, 200
walk, directory, 162
while loop, 75
whitespace, 31, 54, 96, 168, 232
widget, 215, 228
Button, 215
Canvas, 216
Entry, 218
Frame, 220
Label, 215
Menubutton, 223
Text, 218
widget, packing, 220
word count, 167
word frequency, 147, 158
word, reducible, 132, 146
working directory, 162
World module, 180
worst bug, 199
ever, 229
zero, index starting at, 83, 104
zip function, 138
use with dict, 140
Zipf’s law, 158


tải về 1.38 Mb.

Chia sẻ với bạn bè của bạn:
1   ...   75   76   77   78   79   80   81   82   83




Cơ sở dữ liệu được bảo vệ bởi bản quyền ©hocday.com 2024
được sử dụng cho việc quản lý

    Quê hương