!= operator
overloading, 270
string not equal, 23
** exponentiation operator, 17, 34
* operator
list repetition, 28
overloading, 270
in regular expression, 411, 413
+= increment operator, 141
+ operator
list concatenation, 28
overloading, 270
in regular expression, 411, 413
- operator
negation unary operator, 34
overloading, 270
subtraction binary operator, 16, 34
.. parent folder, 111
. regular expression operator, 411, 413
/ operator
overloading, 270
= operator
number less than or equal, 19, 34
overloading, 270
SQL less than or equal, 435
≪≫ SQL not equal operator, 435
≫ operator
overloading, 270
SQL less than, 435
string less than, 23
== operator
string equal, 23
versus = assignment operator, 22
= SQL equal operator, 435
= assignment statement, 12, 20–22, 75–79
multiple assignment, 79
simultaneous assignment, 79
versus == equal operator, 22
>= operator
number greater than or equal, 19, 34
overloading, 270
SQL greater than or equal, 435
> operator
overloading, 270
SQL greater than, 435
string greater than, 23
? regular expression operator, 411, 413
[] operator
dictionary indexing, 175
list slicing, 99
overloading, 287
in regular expression, 411, 413
tuple indexing, 182
two-dimensional list indexing, 147
& set intersection operator, 187, 188
^ operator
in regular expression, 412, 413
set symmetric difference, 187, 188
| operator
in regular expression, 412, 413
abs() built-in function, 17, 34
absolute pathname, 110
accumulator
for integer sum, 141
for integer product, 142
for list concatenation, 142
loop pattern, see iteration pattern
for string concatenation, 142
acronym() function, 142
_ _add_ _() method, 269
add() set method, 188
algebraic
running time, see run time analysis
alignment in formatted output, 107
American Standard Code for Information Interchange (ASCII), 190–191
analyze() function, 416, 420–422
anchor, see HTML
append() list method, 30
Application Programming Interface (API), 7
approxE() function, 152
approxPi() function, 196
Ariane rocket accident, 232
ARPANET, 6
assignment, see = assignment statement
attribute
class, see class
of HTML element, see HTML
instance, see instance
module, see module
automatic indexer, see web crawler
automation, 3
average.py program, 70
background widget option, 311, 314
backslash in file path, 111
base case, see recursion
before0() function, 156
BETWEEN SQL operator, 435
bgcolor() Screen method, 45
binary operator, 20
binary search, 374
binding, see event
blackjack application, 198–202
blackjack() function, 202
bool Boolean type, see Boolean
George Boole, 20
Boolean
algebra, 20
mutability, 76
operators, 19
type, 18
values, 18
borderwidth widget option, 311, 314
bot, see web crawler
browser, see web
bubblesort() function, 145
buffer overflow attack, 222
bug, see computer bug
builtins module, 238
bus, 5
command option, 318
event handler, 318
bye() Screen method, 45
camelCase, 22
canonical string representation, 272–274
capitalize() string method, 100, 102
ceil() math module function, 40
central processing unit (CPU), 4, 455
of files, 194
cheers() recursive function, 356
choice() random module function, 197
chr() built-in function, 191
circle() Turtle method, 43, 44
cities() function, 154
cities2() function, 154
attribute inheritance, 256–257
code reuse, 276
constructor, 36
constructor and repr() contract, 272–276
defining new container, 263–268
documentation, 258
extending a method, 282
method implementation, 243–244
overloaded constructor, 260–262
overloaded indexing operator, 287–289
subclass, 278
superclass, 278
class statement, 255, 257, 279
clear() set method, 188
clearscreen() Screen method, 45
ClickIt class, 332
clickit.py module, 318, 319, 331
client, see web
clock rate, 454
close() Connection method, 442
code point (Unicode), 191
code reuse
with classes, 276
with functions, 216
Collector class, 409
column grid() method option, 316
column formatted output, 106
columnspan grid() method option, 316
command Button widget option, 318
command line, 55
comment, 73
commit() Connection method, 442
compareHands() function, 202
comparison operators, 34
for sets, 188
for strings, 23
compiler, 7
complete() function, 179
computer applications, 2
computer bug, 7
computer virus, see virus
concatenation, see + operator
concurrent, 455
condition
in multiway if statement, 134–137
in one-way if statement, 61, 134
in two-way if statement, 64, 134
in while loop statement, 149
mutually exclusive, 136
connect() sqlite3 function, 441
Connection sqlite3 class, 441
method close(), 442
method commit(), 442
method cursor(), 441
constructor, see class
container class, see class
core (CPU), 454
cos() math module function, 40
count() list method, 30
count() string method, 100, 102
COUNT() SQL function, 436
countdown() recursive function, 352–354
counter loop pattern, see iteration pattern
counting operations, 368
cpu_count() multiprocessing function, 454
crawl1() function, 416
crawl2() function, 419
crawling, see web
CREATE TABLE SQL statement, 439
create_line() widget method, 327, 328
create_rectangle() widget method, 328
create_oval() widget method, 328
current working directory, 110
cursor, 113
Cursor sqlite3 class, 441
as an iterator, 443
method execute(), 441
cursor() Connection method, 441
column, 431
management system, 432
programming, 440
record, 431
row, 431
SQLite, 440
SQLite command-line shell, 433
structured data storage, 431
table, 431
Day class, 334
dealCard() function, 200
debugger, 7
decimal precision in formatted output, 107
decision structure, see if statement
decode() bytes method, 194, 404
def function definition statement, 70
default constructor, see class
default exception handler, see exception
delete() widget method, 328
for Entry, 321
for Text, 323
delimiter for method split(), 100
depth-first traversal, 418–422
DESC SQL clause, 435
dict dictionary type, see dictionary
dict() constructor, 174
key-value pair, 173
multiway condition substitute, 178
mutability, 174
view object, 178
dictionary order (strings), 24, 193
directory, 110
DISTINCT SQL clause, 433
divisors() function, 142
docstring, 73
multiline, 84
double quotes, see string
Draw class, 336
drawKoch() function, 362
dynamic.py module, 72
e math module Euler constant e, 40
elif statement, see if statement
else clause, see if statement
emoticon, 43
EmptyQueueError exception class, 286
encapsulation
with classes, 292
with functions, 217
with user-defined exceptions, 284, 286
end argument, see print()
deleting entry, 321
reading entry, 321
epoch, 123
_ _len_ _() method, 275
error, see exception
escape sequence, 97
”, 96
’, 96
interpreted by print(), 97
in regular expressions, 413
eval() built-in function, 58
event, 319
binding to event handler, 324–329
handler, 318, 319, 324, 337–341
loop, 319
type, 324
attributes, 324
except statement, see exception
catching a type of, 230
catching and handling, 228–235
default handler, 227, 230, 233
exceptional control flow, 227–235
multiple handlers, 231
object, 120
raising, 227
raising in a program, 285
try/except statements, 229–230
type, 120
Exception class, 286
execute() Cursor method, 441
execution control structure, 12–13
expand pack() method option, 314
experimental run time analysis, 370–373
expression
algebraic, see algebraic
Boolean, see Boolean
evaluation, 17
Extender class, 282
factorial()
iterative function, 142
recursive function, 356
False value, 18
feed() HTMLParser method, 406
fetchall() Cursor method, 443, 444
fibonacci() function, 152
field width in formatted output, 107
character encoding, 194
closing, 117
cursor, 113
database, 430
flushing output, 118
mode, 112
reading and writing, 112
storage, 5
absolute pathname, 110
current working directory, 110
directory, 110
folder, 110
pathname, 110
recursive structure, 365
relative pathname, 110
root directory, 110
tree structure, 110
fill pack() method option, 314
findall() re function, 414
First-In First Out (FIFO), 266
float type, see floating point
floating point
float() constructor, 36
mutability, 76
type, 16
floor() math module function, 40
flowchart, 54
three-way if statement, 135
two-way if statement, 63
while loop statement, 149
flushing output, 118
folder, 110
font widget option, 311
for loop statement, 64–67, 137
loop variable, 66
foreground widget option, 311, 314
format() string method, 104–109
format string, 104
for time, 124
forward() Turtle method, 42, 43
forward slash in file path, 111
Koch curve, 360
snowflake, 363
Fraction fractions class, 40
difference between float and, 41
fractions Standard Library module, 40–41
frequency() function, 181
frequent() function, 379
from module import keyword, 241
function
built-in math, 17
call, 29
code reuse, 216
encapsulation, 217
modifying global variable inside, 226
modularity, 217
recursive, see recursion
functional language, 447
geometry (of GUI), see widget
get() dictionary method, 177
get() widget method
for Entry, 321
for Text, 323
getheaders() HTTPResponse method, 404
_ _getitem_ _() method, 288
getpid() os function, 456
getSource() function, 405
geturl() HTTPResponse method, 404
getWordsFromFile() function, 452
global keyword, 226
global variable, 223
storing state in, 328
gmtime() time function, 124
Google, 447
graphical user interface (GUI)
history, 320
object-oriented approach, 331–341
graphics interchange format (GIF), 312
GROUP BY SQL clause, 436
growthrates() function, 109
handle_data() HTMLParser method, 406
handle_endtag() HTMLParser method, 406
handler
exception, see exception
GUI event, see event
HTML document parser, 406
handle_starttag() HTMLParser method, 406
hanoi() recursive function, 380–383
hard drive, 5
hardware, 4
height widget option, 311, 312
hello.py module, 54
hello2() function, 153
help() built-in function, 38
higher-order programming, 371
a anchor element, 401
absolute hyperlink, 402
body element, 401
document tree structure, 401
head element, 401
heading element, 400
href attribute, 402
html element, 401
relative hyperlink, 402
resources, 403
tag, 400
title element, 401
HTMLParser html.parser class, 405
html.parser Standard Library module, 405–408
hyperlink, see HTML
http.client Standard Library module, 403
HTTPResponse http.client class, 403
hyperlink, see HTML
HyperText Markup Language, see HTML
HyperText Transfer Protocol, see HTTP
IDLE, 8
editor, 54
running program, 54
elif statement, 134
ordering of conditions, 136–137
ignore0() function, 157
import statement, see module, 56
ImportError exception, 237
in operator
for dictionaries, 175
for lists, 28
incr2D() function, 148
incrementing, see += increment operator
indentation, 62
indented block
in for loop statement, 67
in function definition, 70
in multiway if statement, 134
in one-way if statement, 61, 134
in two-way if statement, 64, 134
in while loop statement, 149
index, 25
in two-dimensional list, 147
IndexError exception, 119, 120
indexing operator, see [] operator
infinite loop pattern, see iteration pattern
extending a method, 282
overriding a method, 282
subclass, 278
superclass, 278
Inheritor class, 282
_ _init_ _() method, 261–262, 267
input() built-in function, 57
input.py module, 57
insert() list method, 30
insert() widget method
for Entry, 321
for Text, 323
INSERT INTO SQL statement, 439
instance
attribute, 257
int integer type, see integer
integer
int() constructor, 36
mutability, 76
type, 16
integrated development environment (IDE), 7, 8, 54, 56
interactive shell, 8
restarting, 54
interest() function, 150
Internet, 6
IOError exception, 121
items() dictionary method, 177, 184
_ _iter_ _() method, 290
iteration
implementation in new classes, 289–292
through indexes of a list, 138–140
through integers in a range, 68–69, 138
iteration pattern
infinite loop, 153
iteration structure
for loop, see for loop statement
while loop, see while loop statement
iterator, 290
key-value pair
dictionary, 173
MapReduce, 447
KeyboardInterupt exception, 120
KeyError exception, 174
keyLogger.py module, 325
keys() dictionary method, 176, 177
keyword (reserved), 23
koch() recursive function, 361
kthsmallest() function, 378
language
HTML, 397
SQL, 432
left-to-right, 35
left-to-right evaluation, 16
len() built-in function
for dictionaries, 175
for lists, 28
for sets, 187
for strings, 25
lexicographic order, 193
library, 7
line ending in text file, 114
linear search, 374
LinkParser class, 407
Linux, 6
concatenation, see + operator
indexing, see [] operator
length, see len() built-in function
list() constructor, 36
repetition, see * operator
slicing, see [] operator
type, 27
value, 27
listdir() os module function, 366
localtime() time function, 124
log() math module function, 40
log file, 121
motivation, 122
loop and a half pattern, see iteration pattern
lower() string method, 102
Mac OS X, 5
_ _main_ _ module, 238
main memory, 4
mainloop() widget method, 310
maketrans() string method, 101
map() Pool method, 455
map MapReduce function, 450
MapReduce class, 458
name cross-checking, 459
sequential versus parallel, 460
master (widget), see widget
match object (regular expression), 415
math Standard Library module, 39–40
max() built-in function, 18, 28
call, 38
extending, 282
as a function in a namespace, 243–244
inheriting, 282
Microsoft Windows, 5
min() built-in function, 18, 28
mode, see file mode
modularity
through classes, 293
through functions, 217
current working directory, 110
importing all attributes, 241
importing module name, 240
importing some attributes, 240
_ _main_ _ module, 238
user-defined, 56
Moore's Law, 454
move() widget method, 328
multiple assignment, 79
multiprocessing Standard Library module, 454–461
function cpu_count(), 454
mutually exclusive conditions, 136
MyList class, 277
namespace, 219
local, 224
object, 254
and the program stack, 219–223
nested() function, 144
nested loop pattern, see iteration pattern
nested2() function, 145
_ _next_ _() method, 290
numChars() function, 114
numLines() function, 116
numWords() function, 115
object, 31
class attributes inheritance, 256–257
namespace, 254
type, 32
object-oriented programming (OOP), 38, 252–292
Python, 32
occurrences
most frequently occurring item, 379
one-way, see if statement
oneWay.py module, 60
oneWay2.py module, 61
open() built-in function, 111–113, 194
open source, 6
operator, 31
algebraic, see algebraic
Boolean, see Boolean
dictionary, see dictionary
as a function in a namespace, 270
list, see list
overloaded, see class
precedence, see precedence rule
set, see set
string, see string
ord() built-in function, 190
ORDER BY SQL clause, 435
os Standard Library module, 366
getpid() function, 456
listdir() function, 366
path.join() function, 366
OverflowError exception, 33, 120
overloaded, see class
pack() widget method, 311, 313–315
packing widgets, see widget
padx, pady widget options, 311, 314
parallel.py module, 455
versus concurrent, 455
speedup, 457
parallel2.py module, 456
passing functions, 371
parameter substitution (SQL), 441
parent folder, 111
parser, 118
HTML document, see HTML
partition() MapReduce function, 449
path sys module variable, 239
pathsys module variable, 236
path.join() os module function, 366
pathname, 110
absolute, 110
relative, 110
pattern() recursive function, 358
peace.py module, 312
pencolor() Turtle method, 43
pendown() Turtle method, 43, 44
pensize() Turtle method, 43, 44
perimeter.py program, 70
phone.py module, 315
PhotoImage tkinter class, 312
pi math module constant π, 40
placeholder
in format string, 104
in SQL query, 442
plotter.py module, 329
constructor and repr() contract, 272–274
methods, 252
overloaded operators, 268
string representation, 270–272
Pool multiprocessing class, 454–461
method map(), 455
pop() method
list, 30
primeDensity.py module, 457
print() built-in function, 54, 56, 102–104
end argument, 103
sep argument, 102
versus return statement, 71
print2D() function, 147
process, 454
ID, 456
editing, 54
buffer overflow attack, 222
stack frame, 221
programming, 7
language, 7
Project Gutenberg, 460
prompt
input() function, 57
Python shell, see >>> prompt
protocol, 397
HTTP, see HTTP
pseudocode, 11
pseudorandom number generator, 194
Python
background, 8
Standard Library, see Standard Library modules
Queue class, 266–268, 284, 287, 288
empty queue exception, 286
overloaded operators, 269, 274–276
as subclass of list, 283
Queue2 class, 283
QueueIterator class, 291
quotes, see string
raise() built-in function, 285
raising exception, see exception
random Standard Library module, 194–198
random access memory (RAM), see main memory
randomness, 196
randrange() random module function, 195
range() built-in function, 68–69
in counter loop pattern, 138
re Standard Library module, 414–415
read() HTTPResponse method, 404
readline() file method, 112, 113
readlines() file method, 112, 116
real numbers, 33
base case, 353
depth-first traversal, 418–422
function, 352
and the program stack, 356–357
recursive call, 352
recursive step, 354
recursive thinking, 352, 354–356
repeated recursive calls, 362
stopping condition, 353
reduce MapReduce function, 450
escape sequences, 413
resources, 412
algebra, 440
database, 440
relative pathname, 110
relief widget option, 311, 314
remove() method
for lists, 30
for sets, 188
replace() string method, 100, 102
Replacer class, 282
_ _repr_ _() method, 276
repr() built-in function, 271
contract with constructor, 272–276
reserved keywords, 23
result table, see SQL
versus print() built-in function, 71
reverse() list method, 30
reverse() recursive function, 356
reverse index, see inverted index
rfib() recursive function, 369
run time analysis, 372
rlookup() function, 175
root directory, 110
row grid() method option, 316
rowspan grid() method option, 316
rpower() recursive function, 367
linear versus binary search, 376
safe_open() function, 232
sample() random module function, 197
scalability, 445
scan() recursive function, 365
scientific notation, 33
scope, 223
Screen turtle module class
constructor, 42
methods, 45
search() recursive function, 375
search() re function, 415
search engine, 415
binary, 374
duplicates, 377
linear, 374
linear versus binary, 376
search path, see module
selecting k th smallest, 378
sep argument, see print()
SeqMapReduce class, 450
sequence loop pattern, see iteration pattern
server, see web
comparison, 187
constructor, 186
for duplicate removal, 186
empty set, 186
setheading() Turtle method, 43, 45
setup (of Python IDE), 8
setx(), sety() Turtle methods, 43
shell, see interactive shell
shuffle() random module function, 197
shuffledDeck() function, 200
side pack() method option, 313
simultaneous assignment, 79
sin() math module function, 40
single quotes, see string
slicing, see [] operator
smileyPeace.py module, 313
snowflake fractal, 363
software, 4
software library, 7
sort() list method, 30
sorted() function, 140
spelling.py module, 65
split() string method, 100, 102
conditional operators, 435
COUNT() function, 436
CREATE TABLE statement, 439
cross join, 437
DESC clause, 435
DISTINCT clause, 433
GROUP BY clause, 436
INSERT INTO statement, 439
ORDER BY clause, 435
parameter substitution, 441
querying multiple tables, 437
resources, 440
result table, 432
SQL injection, 442
SUM() function, 436
UPDATE statement, 439
SQLite, 440
command-line shell, 433
sqlite3 Standard Library module, 440–445
class Connection, 441
class Cursor, 441
function connect(), 441
sqrt() math module function, 39, 40
stack frame, see program stack
Standard Library modules, 39
fractions, see fractions
html.parser, see html.parser
http.client, see http.client
math, see math
multiprocessing, see multiprocessing
os, see os
random, see random
re, see re
sqlite3, see sqlite3
sys, see sys
time, see time
tkinter, see tkinter
turtle, see turtle
urllib.parse, see urllib.parse
urllib.request, see urllib.request
StopIteration exception, 291
str() string constructor
informal string representation, 272
overloading, 270
str string type, see string
strftime() time function, 124
concatenation, see + operator
encoding, see character encoding
methods return copy, 100
repetition, see * operator
representation of object, 102, 271–274
slicing, see [] operator
str() constructor, see str() constructor
triple quotes, 97
type, 23
value, 23
strip() string method, 102
structured data storage, see database
Structured Query Language, see SQL
subclass, 278
substring, 25
sum() built-in function, 28
SUM() SQL function, 436
superclass, 278
syntax error, 118
sys Standard Library module, 236, 239
table, see database
TCP/IP, 6
temperature() function, 135
text widget option, 311
text entry box
multiline, see Text tkinter class
single-line, see Entry tkinter class
time() time function, 123
time format directive, 124
time Standard Library module, 123–125
timing() function, 371
timingAnalysis() function, 372
Tk tkinter class, 310
tkinter Standard Library module, 310
coordinate system, 330
resources, 317
widgets, see widget
total() (Blackjack) function, 201
Tower of Hanoi problem, 379–385
translate() string method, 101, 102
tree
filesystem, 110
of recursive calls, 373
root, 401
structure of HTML document, 401
triple quotes, 97
True value, 18
truth table, 20
try statement, see exception
mutability, 182
one-element tuple, 184
Turtle turtle class
constructor, 42
turtle Standard Library module, 41–45
Screen class, see Screen
Turtle class, see Turtle
turtlefunctions.py module, 82
turtles() Screen method, 45
two-way, see if statement
twoWay.py module, 63
in formatted output, 108
type() built-in function, 32
type conversion
explicit, 37
unary operator, 20
uniform() random module function, 196
Uniform Resource Locator, see URL
uniqueness testing, 377
UNIX, 5
update() dictionary method, 176, 177
UPDATE SQL statement, 439
upper() string method, 100, 102
absolute, 402
host, 397
pathname, 397
relative, 402
scheme, 397
urljoin() urllib.parse function, 409
urllib.request Standard Library module, 403–405
urllib.parse Standard Library module, 408–409
urlopen() urllib.request function, 403
user-defined
module, 56
user-defined indexes, see dictionary
UTC time, 123
ValueError exception, 120
Van Rossum, Guido, 8
evaluation of, 21
global, 223
naming convention, 22
type, 32
unassigned, 21
vertical() recursive function, 354
view object, 178
virus, 364
signature, 364
web, 396
client, 396
page source file, 399
server, 396
server root directory, 397
widget, 310
coordinate system, 330
mainloop() widget method, 310
mixing pack() and grid(), 316
placement, 311
placement with grid(), 315–317
placement with pack(), 313–315
Tk, 310
wordcount() function, 181
World Wide Web, see WWW
wrapper function, 122
history, 396
HTML, see HTML
HTTP, see HTTP
locator scheme, 397
naming scheme, 397
technologies, 397
URL, see URL