Please note that index links to approximate location of each term.
Symbols
+ (addition), 26
+= (addition in place), 122
* (arbitrary arguments), 146
** (arbitrary keyword arguments), 148
{} (braces)
dictionaries, 92
sets, 104
/ (division), 26
** (exponent), 26
> (greater than), 75
>= (greater than or equal to), 75
# (hash mark), for comments, 29
!= (inequality), 74
< (less than), 75
<= (less than or equal to), 75
[] (list), 34
% (modulo), 116
+= (multiline strings), 115
* (multiplication), 26
\n (newline), 22
>>> (Python prompt), 4
- (subtraction), 26
\t (tab), 22
_ (underscore)
in file and folder names, 10
in numbers, 28
in variable names, 17
A
Alien Invasion. See also Pygame
checking edges, 265
collisions, with bullets, 267
collisions, with ship, 270–273
controlling fleet direction, 264–266
reaching bottom of screen, 273–274
collisions, with aliens, 267
larger, 268
settings, 247
speeding up, 269
classes
Alien, 257
AlienInvasion, 229
GameStats, 271
Settings, 232
initializing dynamic settings, 283–285
levels
modifying speed settings, 283–285
resetting the speed, 285
planning, 228
deactivating, 282
starting game, 281
reviewing the project, 256
all hits, 290
increasing point values, 290–291
rounding and formatting, 291–292
score attribute, 286
updating, 289
and keyword, 75
antialiasing, 279
API. See application programming interface
application programming interface (API), 355
GitHub API, 368
processing an API response, 357–362
rate limits, 362
arguments, 131. See also under functions
attributes, 159. See also under classes
B
Boolean values, 77
Bootstrap, 433. See also unxder Django
braces ({})
dictionaries, 92
sets, 104
break statement, 121
built-in functions, 467
C
calls (functions), 130, 132–135
cities.py, 121
classes
attributes, 159
accessing, 160
attributes and methods, 169
composition, 170
instances as attributes, 170–172
overriding methods, 170
parent classes, 170
subclasses, 168
super() function, 168
superclasses, 168
instances, 157
methods, 159
calling, 160
chaining, 185
__init()__ method, 159
modeling real-world objects, 172–173
multiple instances, 161
naming conventions, 158
objects, 157
style guidelines, 181
comma-separated value files. See CSV files
comment.py, 29
conditional tests, 72–77. See also if statements
constants, 28
continue statement, 122
csv.reader() function, 330–333
D
data analysis, 301
databases. See under Django
data visualization, 301. See also Matplotlib; Plotly
death_valley_highs_lows.py, 339–341
default values
definition (functions), 130
def keyword, 130
del statement
with dictionaries, 96
dictionaries
defining, 92
empty, 94
KeyError, 98
key-value pairs, 92
removing, 96
looping through
methods
nesting
dictionaries in dictionaries, 110–111
dictionaries in lists, 105–108
lists in dictionaries, 108–109
sorting a list of, 370
values
die.py, 320
div (HTML), 437
division_calculator.py, 192–195
Django. See also Git; Learning Log project
associating data with a user, 425–430
card, 443
collapsible navigation, 437
container, 440
django-boostrap5 app, 434
documentation, 444
list groups, 443
commands
createsuperuser, 382
flush, 427
migrate, 377
shell, 386
startproject, 376
creating new projects, 376
databases
cascading delete, 384
creating, 376
many-to-one relationships, 384
non-nullable field, 427
Postgres, 447
querysets, 386–387, 395, 398, 426–428
resetting, 427
SQLite, 377
committing the project, 453
creating Platform.sh project, 453–455
deleting projects, 461
free trial limits, 446
gunicorn, 447
installing Platform.sh CLI, 446, 497–500
installing platformshconfig, 446
other deployment approaches, 500
Platform.sh, 445
Postgres database, 447, 450–451
psycopg2, 447
pushing a project, 455
requirements.txt, 446
settings, 451
using Git, 451
viewing project, 456
development server, 377–378, 383, 392
documentation
model fields, 380
queries, 388
templates, 400
csrf_token, 407
GET and POST requests, 406
processing forms, 405–406, 409–410, 412–413, 421–422, 429–430
save() method, 405–406, 409–410, 430
templates, 407, 410–411, 413, 417, 419, 422
widgets, 408
HTML
anchor tag (<a>), 393
<body> element, 437
comments, 437
<div> elements, 437
<main> element, 440
margins, 440
padding, 440
<p> elements, 391
<span> elements, 438
HTTP 404 error, 428–429, 459–460
INSTALLED_APPS, 380
localhost, 378
@login_required decorator, 423–424
login template, 417
mapping URLs, 388–390, 397–398
migrating the database, 426–427
models, 379
registering with admin, 382–383, 385–386
projects (vs. apps), 379
release cycle, 376
restricting access to data, 427–430
settings
ALLOWED_HOSTS, 451
INSTALLED_APPS, 380–381, 415–416, 434
LOGIN_URL, 424
LOGOUT_REDIRECT_URL, 420
SECRET_KEY, 451
starting an app, 379
styling. See Django: Bootstrap
templates
block tags, 393
context dictionary, 395
filters, 399
forms in, 407
indentation in, 393
linebreaks, 399
template tags, 393
user object, 418
URLs. See Django: mapping URLs
user ID values, 426
versions, 376
E
earthquakes. See mapping earthquakes
enumerate() function, 331
equality operator (==), 72, 74
even_numbers.py, 58
even_or_odd.py, 117
deciding which errors to report, 199
try-except blocks, 193
exponents (**), 26
F
favorite_languages.py, 96–97, 100–104, 109
files
file paths, 186
absolute, 186
pathlib module, 184
relative, 186
from strings, 198
on Windows, 186
read_text() method, 185, 195–196
first_numbers.py, 57
for loops, 49–56, 99–104. See also dictionaries; lists
f-strings
full_name.py, 21
arguments
errors, 136
body, 130
built-in, 467
calling functions, 130, 132–135
defining, 130
specific functions, 151
modifying a list in a function, 142–145
parameters, 131
style guidelines, 153
G
GeoJSON files, 342–347, 350–351
GET requests, 406. See Django: forms
getting help
Discord, 480
official Python documentation, 479–480
r/learnpython, 480
rubber duck debugging, 478
searching online, 479
Slack, 481
Stack Overflow, 479
Git, 356, 451–453, 483–492. See also Django: deployment
adding files, 486
branches, 486
checking out previous commits, 489–491
deleting a repository, 491–492
.gitignore, 484
HEAD, 490
ignoring files, 484
initializing a repository, 485
installing, 484
log, 487
repositories, 356
GitHub, 356
greet_users.py, 142
H
hash mark (#), for comments, 29
I
IDE (integrated development environment), 469–470
if statements
and keyword, 75
Boolean expressions, 77
checking for
equality (==), 72
inequality (!=), 74
item in list, 76
item not in list, 76
if statements and lists, 85–88
or keyword, 76
simple, 78
style guidelines, 89
testing multiple conditions, 82–83
immutable, 65
inheritance, 167–173. See also under classes
insert() method, 38
itemgetter() function, 370
J
JSON files
GeoJSON files, 342–347, 350–351
JSON data format, 201
json.dumps() function, 201–204, 343–344, 368
json.loads() function, 201–204, 343–344
K
key-value pairs, 92. See also dictionaries
keywords, 466
L
language_survey.py, 219
Learning Log project, 373
files, 392
404.html, 459
500.html, 459
base.html, 392–393, 396, 418–419, 422, 435–440
edit_entry.html, 413
learning_logs/urls.py, 389–390, 394–395, 397–398, 405, 409, 412
learning_logs/views.py, 390, 395, 398, 405–406, 409–410, 412–413, 423–425, 428–430
ll_project/urls.py, 388–389, 416
new_entry.html, 410
new_topic.html, 407
register.html, 422
routes.yaml, 450
services.yaml, 450
settings.py, 380–381, 415–418, 420, 424, 434, 451, 457–460
ongoing development, 460
pages, 391
writing a specification (spec), 374
library, 184
Linux
Python
checking installed version, 8
terminals
running programs from, 12
starting Python session, 9
troubleshooting installation issues, 10
VS Code, installing, 9
lists, 33
elements
accessing, 34
accessing last, 35
adding with insert(), 38
identifying unique, 104
enumerate() function, 331
errors
index, 46
negative index, 35
nesting
dictionaries in lists, 105–108
lists in dictionaries, 108–109
max() function, 59
min() function, 59
sum() function, 59
removing all occurrences of a value, 125
sorting
reverse() method, 44
sort() method, 43
square brackets, 34
logical errors, 54
M
macOS
.DS_Store files, ignoring, 453
Homebrew package manager, 499
Python
checking installed version, 7
terminals
running programs from, 12
starting Python session, 7
troubleshooting installation issues, 10
VS Code, installing, 8
magic_number.py, 74
mapping earthquakes, 342–352. See also Plotly
GeoJSON files, 342–347, 350–351
latitude-longitude ordering, 345
magnitudes, 346
Matplotlib
axes
removing, 317
ax objects, 303
fig objects, 303
figsize argument, 318
formatting plots
built-in styles, 306
custom colors, 310
plot size, 318
gallery, 302
installing, 302
savefig() method, 311
saving plots, 311
subplots() function, 303
methods, 20
helper methods, 237
modules, 149–152, 173–179. See also classes: importing; functions: importing
my_electric_car.py, 176
N
name.py, 20
nesting. See dictionaries: nesting; lists: for loops
number_reader.py, 202
arithmetic, 26
constants, 28
exponents, 26
integers, 26
mixing integers and floats, 27–28
order of operations, 26
underscores in, 28
number_writer.py, 201
O
object-oriented programming (OOP), 157. See also classes
or keyword, 76. See also if statements
P
pandas, 320
parameters, 131
paths. See files: file paths
installing Matplotlib, 302
installing Plotly, 320
installing Pygame, 228
installing pytest, 211
installing Requests, 357
Linux, installing pip, 465–466
updating, 210
Platform.sh. See Django: deployment
Plotly, 302, 319. See also mapping earthquakes; rolling dice
chart types, 322
customizing plots, 323, 325–326, 364
documentation, 368
fig.show() method, 322
fig.write_html() method, 327
formatting plots
axis labels, 323
titles, 323
update_layout() method, 325–326, 364
update_traces() method, 367
gallery, 320
histograms, 322
installing, 320
plotly.express module, 322, 347, 368
px alias, 322
px.bar() function, 322–323, 363–367
saving figures, 327
scatter_geo() function, 347–352
positional arguments, 131–133. See also functions: arguments
POST requests, 406. See also Django: forms
Pygame. See also Alien Invasion
collisions, 266–267, 270–271, 289–290
creating an empty window, 229–230
fullscreen mode, 245
groups
drawing all elements in, 249–250, 257–258
removing elements from, 250–251
updating all elements in, 248–249
installing, 228
print() calls in, 251
creating from scratch, 247–248
positioning, 234–235, 238–243, 247–248, 256–262, 278, 286–298
size attribute, 261
responding to input, 230
events, 230
screen coordinates, 235
surfaces, 230
testing games, 268
pytest. See testing code
Python
>>> prompt, 4
built-in functions, 467
checking installed version, 466
installing
keywords, 466
Python Enhancement Proposal (PEP), 68
terminal sessions, 4
on Linux, 9
on Windows, 6
versions, 4
why use Python, xxxvi
python_repos_visual.py, 362–367
Q
quit values, 118
R
choice() function, 313
generating multiple walks, 314–315
starting and ending points, 316–317
read_text() method, 185, 195–196
refactoring, 204–206, 237–238, 260, 269–270
removeprefix() method, 24
removesuffix() method, 25
Requests package, installing, 357
rollercoaster.py, 116
rolling dice, 319–327. See also Plotly
Die class, 320
randint() function, 320
rubber duck debugging, 478
S
sleep() function, 272
sorted() function, 43–44, 102–103
sort() method, 43
Stack Overflow, 479
storing data, 201–204. See also JSON files
saving and reading data, 202–204
changing case, 20
methods
lower(), 20
removesuffix(), 25
title(), 20
upper(), 20
multiline, 115
single and double quotes, 19, 24–25
blank lines, 69
CamelCase, 181
classes, 181
functions, 153
if statements, 89
indentation, 68
line length, 69
PEP 8, 68
survey.py, 218
syntax errors, 24
syntax highlighting, 16
T
templates. See under Django
full coverage, 212
naming tests, 213
test cases, 212
unit tests, 212
test_name_function.py, 212–217
text editors and IDEs. See also VS Code
Emacs and Vim, 475
Geany, 474
IDLE, 474
Jupyter Notebooks, 475
PyCharm, 475
Sublime Text, 474
third-party package, 210
tracebacks, 10, 17–18, 192, 195–196
try-except blocks. See exceptions
defining, 65
writing over, 67
type errors, 66
U
underscore (_)
in file and folder names, 10
in numbers, 28
in variable names, 17
unit tests, 212
V
constants, 28
multiple assignment, 28
naming conventions, 17
values, 16
version control. See Git
installing
on Linux, 9
on macOS, 8
on Windows, 6
opening files with Python, 185
Python extension, 9
running files, 10
tabs and spaces, 471
W
weather data, 330–341. See also CSV files; Matplotlib
break statement, 121
continue statement, 122
moving items between lists, 124
quit values, 118
removing all items from list, 125
whitespace, 21–23. See also strings
Windows
file paths, 186
Python
setting up, 5–6, 9–12, 463–464
troubleshooting installation, 10
terminals
running programs from, 12
starting Python session, 6
VS Code, installing, 6
Z