Cover....1
Half Title....2
Title Page....4
Copyright Page....5
Contents....6
Preface....20
Improvements in the Fifth Edition....20
Acknowledgments....21
MODULE 1 Getting Started in Python....22
Exercise 0 Gearing Up....23
General Instructions....23
Minimalist Start....24
Complete Instructions....24
Testing Your Setup....24
Learning the Command Line....25
Next Steps....26
Exercise 1 A Good First Program....27
What You Should See....28
Study Drills....29
Common Student Questions....30
The Blue Plus....30
Exercise 2 Comments and Pound Characters....31
What You Should See....31
Study Drills....31
Common Student Questions....32
Exercise 3 Numbers and Math....33
What You Should See....34
Study Drills....34
Common Student Questions....34
Exercise 4 Variables and Names....37
What You Should See....38
Study Drills....38
Common Student Questions....38
Exercise 5 More Variables and Printing....41
What You Should See....41
Study Drills....42
Common Student Questions....42
Exercise 6 Strings and Text....43
What You Should See....44
Study Drills....44
Break It....44
Common Student Questions....45
Exercise 7 Combining Strings....47
What You Should See....47
Study Drills....47
Break It....48
Common Student Questions....48
Exercise 8 Formatting Strings Manually....49
What You Should See....49
Study Drills....50
Common Student Questions....50
Exercise 9 Multi-Line Strings....51
What You Should See....51
Study Drills....52
Common Student Questions....52
Exercise 10 Escape Codes in Strings....53
What You Should See....54
Escape Sequences....54
Study Drills....55
Common Student Questions....55
Exercise 11 Asking People Questions....57
What You Should See....57
Study Drills....58
Common Student Questions....58
Exercise 12 An Easier Way to Prompt....59
What You Should See....59
Study Drills....59
Common Student Questions....60
Exercise 13 Parameters, Unpacking, Variables....61
If You Get Lost....62
Code Description....62
Hold Up! Features Have Another Name....63
What You Should See....63
Study Drills....64
Common Student Questions....64
Exercise 14 Prompting and Passing....67
What You Should See....68
Study Drills....68
Common Student Questions....68
Exercise 15 Reading Files....71
What You Should See....72
Study Drills....72
Common Student Questions....73
Exercise 16 Reading and Writing Files....75
What You Should See....76
Study Drills....76
Common Student Questions....77
Exercise 17 More Files....79
What You Should See....80
Study Drills....80
Common Student Questions....80
MODULE 2 The Basics of Programming....82
Exercise 18 Names, Variables, Code, Functions....83
Exercise Code....84
What You Should See....86
Study Drills....86
Common Student Questions....87
Exercise 19 Functions and Variables....89
What You Should See....90
Study Drills....91
Common Student Questions....91
Exercise 20 Functions and Files....93
What You Should See....94
Study Drills....94
Common Student Questions....95
Exercise 21 Functions Can Return Something....97
What You Should See....98
Study Drills....98
Common Student Questions....99
Exercise 22 Strings, Bytes, and Character Encodings....101
Initial Research....101
Switches, Conventions, and Encodings....103
Dissecting the Output....105
Dissecting the Code....105
Encodings Deep Dive....107
Breaking It....108
Exercise 23 Introductory Lists....109
Accessing Elements of a List....109
Practicing Lists....110
The Code....110
The Challenge....111
Fruit Challenge....111
Cars Challenge....111
Languages Challenge....112
Final Challenge....112
Exercise 24 Introductory Dictionaries....113
Key/Value Structures....113
Combining Lists with Data Objects....114
The Code....115
What You Should See....116
The Challenge....116
Fruit Challenge....116
Cars Challenge....116
Languages Challenge....117
Final Challenge....117
Exercise 25 Dictionaries and Functions....119
Step 1: Function Names Are Variables....119
Step 2: Dictionaries with Variables....119
Step 3: Dictionaries with Functions....120
Step 4: Deciphering the Last Line....120
Study Drill ....121
Exercise 26 Dictionaries and Modules....123
Step 1: Review of import....123
Step 2: Find the __dict__....123
Step 3: Change the __dict__....124
Study Drill: Find the “Dunders”....125
Exercise 27 The Five Simple Rules to the Game of Code....127
Rule 1: Everything Is a Sequence of Instructions....127
How can I get this output?....128
Where are these bytes stored?....129
Rule 2: Jumps Make the Sequence Non-Linear....129
Why is this backward?....130
Can a JUMP go forward?....130
Rule 3: Tests Control Jumps....131
What do you mean “pop”?....132
Wait, aren’t tests like COMPARE_OP used in loops too?....132
Rule 4: Storage Controls Tests....132
Rule 5: Input/Output Controls Storage....133
Putting It All Together....134
The List of Byte Codes....134
dis() Is a Side Quest....135
Exercise 28 Memorizing Logic....137
The Truth Terms....137
The Truth Tables....138
Common Student Questions....140
Exercise 29 Boolean Practice....141
What You Should See....143
Study Drills....143
Common Student Questions....143
Exercise 30 What If....145
What You Should See....145
dis() It ....146
Study Drill....146
Common Student Questions....146
Exercise 31 Else and If....147
What You Should See....148
dis() It....148
Study Drills....149
Common Student Questions....149
Exercise 32 Making Decisions....151
What You Should See....152
dis() It....152
Study Drills....153
Common Student Questions....153
Exercise 33 Loops and Lists....155
What You Should See....156
dis() It ....157
Study Drills....158
Common Student Questions....158
Exercise 34 While Loops....159
What You Should See....160
dis() It....160
Study Drills....161
Common Student Questions....161
Exercise 35 Branches and Functions....163
What You Should See....164
Study Drills....165
Common Student Questions....165
Exercise 36 Designing and Debugging....167
From Idea to Working Code....167
Is This a Professional Process?....168
About the “X/Y” Non-Problem....169
Rules for If-Statements....170
Rules for Loops....170
Tips for Debugging....170
Homework....171
Exercise 37 Symbol Review....173
Keywords....173
Data Types....174
String Escape Sequences....175
Old-Style String Formats....175
Operators....176
Reading Code....177
Study Drills....178
Common Student Questions....178
MODULE 3 Applying What You Know....180
Exercise 38 Beyond Jupyter for Windows....181
Why Learn PowerShell?....182
What Is PowerShell?....182
PowerShell versus Cmder....184
Starting Jupyter....184
Getting Help....185
Where Are You with start?....185
Going from Graphics to PowerShell....186
Where Are You with pwd?....186
What’s in Here?....187
Files, Folders, Directories, and Paths....188
Moving Around....188
Relative Paths....189
Creating and Destroying....190
Flags and Arguments....190
Copy and Move....190
Environment Variables....191
Running Code....191
Common Key Sequences....192
Useful Developer Commands....192
Crash Landing....192
Exercise 39 Beyond Jupyter for macOS/Linux....193
macOS Troubles....194
Why Learn Bash or ZSH?....194
What Is Bash?....194
Starting Jupyter....196
Getting Help....196
Where Are You with open?....196
Going from Graphics to Bash....197
Where Are You with pwd?....198
What’s in Here?....198
Files, Folders, Directories, and Paths....199
Moving Around....200
Relative Paths....200
Creating and Destroying....201
Hidden Files....201
Flags and Arguments....202
Copy and Move....202
Environment Variables....203
Running Code....203
Common Key Sequences....204
Useful Developer Commands....204
Crash Landing....205
Exercise 40 Advanced Developer Tools....207
Managing conda Environments....207
Adding conda-forge....208
Using pip....209
Using a .condarc....209
General Editing Tips....210
Going Further....210
Exercise 41 A Project Skeleton....211
Activate an Environment....211
Just Use cookiecutter....211
Building Your Project....212
Installing Your Project....212
Testing the Install....213
Remove test-project....213
Common Errors....214
Study Drills....214
Exercise 42 Doing Things to Lists....215
What You Should See....216
What Lists Can Do....217
When to Use Lists....218
Study Drills....218
Common Student Questions....219
Exercise 43 Doing Things to Dictionaries....221
A Dictionary Example....222
What You Should See....224
What Dictionaries Can Do....224
Study Drills....225
Common Student Questions....225
Exercise 44 From Dictionaries to Objects....227
Step 1: Passing a Dict to a Function....227
What You Should See....228
Step 2: talk inside the Dict....228
Step 3: Closures....229
What You Should See....230
Step 4: A Person Constructor....230
Study Drills....232
Exercise 45 Basic Object-Oriented Programming....233
Python’s People....233
Using dir() and __dict__....234
About the Dot (.)....235
Terminology....236
A Word on self....237
Study Drills....238
Common Student Questions....238
Exercise 46 Inheritance and Advanced OOP....239
How This Looks in Code....240
About class Name(object)....242
Study Drills....242
Common Student Questions....243
Exercise 47 Basic Object-Oriented Analysis and Design....245
The Analysis of a Simple Game Engine....246
Write or Draw About the Problem....246
Extract Key Concepts and Research Them....247
Create a Class Hierarchy and Object Map for the Concepts....247
Code the Classes and a Test to Run Them....248
Repeat and Refine....250
Top Down versus Bottom Up....250
The Code for “Gothons from Planet Percal #25”....251
What You Should See....257
Study Drills....258
Common Student Questions....258
Exercise 48 Inheritance versus Composition....259
What Is Inheritance?....259
Implicit Inheritance....260
Override Explicitly....261
Alter Before or After....261
All Three Combined....263
The Reason for super()....264
Using super() with __init__()....264
Composition....264
When to Use Inheritance or Composition....266
Study Drill....266
Common Student Questions....267
Exercise 49 You Make a Game....269
Evaluating Your Game....269
Function Style....270
Class Style....270
Code Style....271
Good Comments....271
Evaluate Your Game....271
Exercise 50 Automated Testing....273
What Is the Purpose of Testing?....273
How to Test Efficiently....273
Install PyTest ....274
Simple PyTest Demo....275
Running pytest....276
Exceptions and try/except....276
Getting Coverage Reports....277
Study Drills....277
Common Student Questions....278
MODULE 4 Python and Data Science....280
Exercise 51 What Is Data Munging?....281
Why Data Munging?....282
The Problem....282
The Setup....283
How to Code....283
Process Example....284
Solution Strategies....286
Awesome ETL Tools....287
Study Drills....287
Exercise 52 Scraping Data from the Web....289
Introducing with....289
The Problem....290
The Setup....290
The Clue....291
Awesome Scraping Tools....291
Study Drills....292
Exercise 53 Getting Data from APIs....293
Introducing JSON....293
The Problem....294
The Setup....295
The Clue....295
Awesome API Tools....296
Study Drills....296
Exercise 54 Data Conversion with pandas....297
Introducing Pandoc....297
The Problem....297
The Setup....298
The Clue....298
Study Drills....299
Exercise 55 How to Read Documentation (Featuring pandas)....301
Why Programmer Documentation Sucks....301
How to Actively Read Programmer Docs....302
Step #1: Find the Docs....302
Step #1 with pandas....302
Step #2: Determine Your Strategy....303
Step #2 with pandas....303
Step #3: Code First, Docs Second....304
Step #3 with pandas....304
Step #4: Break or Change the Code....304
Step #5: Take Notes....305
Step #6: Use It on Your Own....305
Step #6 with pandas....305
Step #7: Write About What You Learned....305
Step #7 with pandas....306
Step #8: What’s the Gestalt?....306
Step #8 with pandas....307
Reading My pandas Curriculum....307
Exercise 56 Using Only pandas....309
Make a Project....309
The Problem....309
The Setup....310
Study Drill....310
Exercise 57 The SQL Crash Course....311
What Is SQL?....311
The Setup....312
Fixing and Loading....313
Back Up Your Database....313
Create, Read, Update, Delete....314
SELECT....314
Date and Time....315
INSERT....316
UPDATE....317
DELETE and Transactions....318
Math, Aggregates, and GROUP BY....319
Python Access....320
Exercise 58 SQL Normalization....321
What Is Normalization?....321
First Normal Form....322
Implementing 1NF....323
Creating Tables in SQL....324
Second Normal Form (2NF)....324
Implementing 2NF....325
Using Python....327
Querying 2NF Data....327
Querying with Joins....329
Study Drills....329
Exercise 59 SQL Relationships....331
One-to-Many (1:M)....331
One-to-Many in Python....331
One-to-Many Problem....332
Many-to-Many (M:M)....332
Many-to-Many Problem....333
One-to-One (1:1)....333
Attributed Relations....334
Querying M:M Tables....334
Your Last Study Drill....335
Exercise 60 Advice from an Even Older Programmer....337
Index....339
A....339
B....339
C....340
D....340
E....341
F....341
G....342
H....342
I....342
J....342
K....342
L....342
M....343
N....343
O....343
P....343
R....344
S....344
T....345
U....345
V....345
W....345
X....345
Z....345
In Learn Python the Hard Way, Fifth Edition, you'll learn Python by working through 60 lovingly crafted exercises. Read them. Type in the code. Run it. Fix your mistakes. Repeat. As you do, you'll learn how a computer works, how to solve problems, and how to enjoy programming . . . even when it's driving you crazy.
It'll be frustrating at first. But if you keep trying, you'll get it--and it'll feel amazing! This course will reward you for every minute you put into it. Soon, you'll know one of the world's most powerful, popular programming languages. You'll be a Python programmer.
This Book Is Perfect For
Register your book for convenient access to downloads, updates, and/or corrections as they become available. See inside book for details.