| 1 Why should you learn to write programs? |
|
1 | (16) |
|
1.1 Creativity and motivation |
|
|
2 | (1) |
|
1.2 Computer hardware architecture |
|
|
3 | (1) |
|
1.3 Understanding programming |
|
|
4 | (1) |
|
|
|
5 | (1) |
|
1.5 Conversing with Python |
|
|
6 | (2) |
|
1.6 Terminology: interpreter and compiler |
|
|
8 | (2) |
|
|
|
10 | (1) |
|
|
|
10 | (1) |
|
1.9 The building blocks of programs |
|
|
11 | (1) |
|
1.10 What could possibly go wrong? |
|
|
12 | (2) |
|
1.11 The learning journey |
|
|
14 | (1) |
|
|
|
14 | (1) |
|
|
|
15 | (2) |
| 2 Variables, expressions, and statements |
|
17 | (12) |
|
|
|
17 | (1) |
|
|
|
18 | (1) |
|
2.3 Variable names and keywords |
|
|
19 | (1) |
|
|
|
19 | (1) |
|
2.5 Operators and operands |
|
|
20 | (1) |
|
|
|
21 | (1) |
|
|
|
21 | (1) |
|
|
|
22 | (1) |
|
|
|
22 | (1) |
|
2.10 Asking the user for input |
|
|
22 | (1) |
|
|
|
23 | (1) |
|
2.12 Choosing mnemonic variable names |
|
|
24 | (2) |
|
|
|
26 | (1) |
|
|
|
27 | (1) |
|
|
|
27 | (2) |
| 3 Conditional execution |
|
29 | (12) |
|
|
|
29 | (1) |
|
|
|
30 | (1) |
|
3.3 Conditional execution |
|
|
30 | (1) |
|
3.4 Alternative execution |
|
|
31 | (1) |
|
|
|
32 | (1) |
|
|
|
33 | (1) |
|
3.7 Catching exceptions using try and except |
|
|
34 | (1) |
|
3.8 Short-circuit evaluation of logical expressions |
|
|
35 | (2) |
|
|
|
37 | (1) |
|
|
|
37 | (1) |
|
|
|
38 | (3) |
| 4 Functions |
|
41 | (14) |
|
|
|
41 | (1) |
|
|
|
41 | (1) |
|
4.3 Type conversion functions |
|
|
42 | (1) |
|
|
|
43 | (1) |
|
|
|
44 | (1) |
|
|
|
45 | (1) |
|
|
|
46 | (1) |
|
|
|
47 | (1) |
|
4.9 Parameters and arguments |
|
|
48 | (1) |
|
4.10 Fruitful functions and void functions |
|
|
49 | (1) |
|
|
|
50 | (1) |
|
|
|
50 | (1) |
|
|
|
51 | (1) |
|
|
|
52 | (3) |
| 5 Iteration |
|
55 | (10) |
|
|
|
55 | (1) |
|
|
|
55 | (1) |
|
|
|
56 | (1) |
|
5.4 "Infinite loops" and break |
|
|
56 | (1) |
|
5.5 Finishing iterations with continue |
|
|
57 | (1) |
|
5.6 Definite loops using for |
|
|
58 | (1) |
|
|
|
59 | (3) |
|
5.7.1 Counting and summing loops |
|
|
59 | (1) |
|
5.7.2 Maximum and minimum loops |
|
|
60 | (2) |
|
|
|
62 | (1) |
|
|
|
62 | (1) |
|
|
|
62 | (3) |
| 6 Strings |
|
65 | (12) |
|
6.1 A string is a sequence |
|
|
65 | (1) |
|
6.2 Getting the length of a string using len |
|
|
66 | (1) |
|
6.3 Traversal through a string with a loop |
|
|
66 | (1) |
|
|
|
67 | (1) |
|
6.5 Strings are immutable |
|
|
68 | (1) |
|
|
|
68 | (1) |
|
|
|
69 | (1) |
|
|
|
69 | (1) |
|
|
|
69 | (3) |
|
|
|
72 | (1) |
|
|
|
72 | (1) |
|
|
|
73 | (1) |
|
|
|
74 | (1) |
|
|
|
75 | (2) |
| 7 Files |
|
77 | (12) |
|
|
|
77 | (1) |
|
|
|
78 | (1) |
|
|
|
79 | (1) |
|
|
|
80 | (1) |
|
7.5 Searching through a file |
|
|
81 | (2) |
|
7.6 Letting the user choose the file name |
|
|
83 | (1) |
|
7.7 Using try, except, and open |
|
|
84 | (1) |
|
|
|
85 | (1) |
|
|
|
86 | (1) |
|
|
|
86 | (1) |
|
|
|
87 | (2) |
| 8 Lists |
|
89 | (16) |
|
|
|
89 | (1) |
|
|
|
90 | (1) |
|
|
|
90 | (1) |
|
|
|
91 | (1) |
|
|
|
92 | (1) |
|
|
|
92 | (1) |
|
|
|
93 | (1) |
|
|
|
94 | (1) |
|
|
|
95 | (1) |
|
|
|
96 | (1) |
|
|
|
97 | (1) |
|
|
|
98 | (1) |
|
|
|
98 | (2) |
|
|
|
100 | (3) |
|
|
|
103 | (1) |
|
|
|
103 | (2) |
| 9 Dictionaries |
|
105 | (10) |
|
9.1 Dictionary as a set of counters |
|
|
107 | (1) |
|
9.2 Dictionaries and files |
|
|
108 | (1) |
|
9.3 Looping and dictionaries |
|
|
109 | (2) |
|
9.4 Advanced text parsing |
|
|
111 | (1) |
|
|
|
112 | (1) |
|
|
|
113 | (1) |
|
|
|
113 | (2) |
| 10 Tuples |
|
115 | (12) |
|
10.1 Tuples are immutable |
|
|
115 | (1) |
|
|
|
116 | (2) |
|
|
|
118 | (1) |
|
10.4 Dictionaries and tuples |
|
|
119 | (1) |
|
10.5 Multiple assignment with dictionaries |
|
|
120 | (1) |
|
10.6 The most common words |
|
|
121 | (1) |
|
10.7 Using tuples as keys in dictionaries |
|
|
122 | (1) |
|
10.8 Sequences: strings, lists, and tuples - Oh My! |
|
|
122 | (1) |
|
|
|
123 | (1) |
|
|
|
124 | (1) |
|
|
|
125 | (2) |
| 11 Regular expressions |
|
127 | (14) |
|
11.1 Character matching in regular expressions |
|
|
128 | (1) |
|
11.2 Extracting data using regular expressions |
|
|
129 | (3) |
|
11.3 Combining searching and extracting |
|
|
132 | (3) |
|
|
|
135 | (1) |
|
|
|
136 | (1) |
|
11.6 Bonus section for Unix/Linux users |
|
|
137 | (1) |
|
|
|
137 | (1) |
|
|
|
138 | (1) |
|
|
|
138 | (3) |
| 12 Networked programs |
|
141 | (12) |
|
12.1 HyperText Transport Protocol - HTTP |
|
|
141 | (1) |
|
12.2 The World's Simplest Web Browser |
|
|
142 | (1) |
|
12.3 Retrieving an image over HTTP |
|
|
143 | (3) |
|
12.4 Retrieving web pages with urllib |
|
|
146 | (1) |
|
12.5 Parsing HTML and scraping the web |
|
|
147 | (1) |
|
12.6 Parsing HTML using regular expressions |
|
|
147 | (1) |
|
12.7 Parsing HTML using BeautifulSoup |
|
|
148 | (2) |
|
12.8 Reading binary files using urllib |
|
|
150 | (1) |
|
|
|
151 | (1) |
|
|
|
152 | (1) |
| 13 Using Web Services |
|
153 | (14) |
|
13.1 eXtensible Markup Language - XML |
|
|
153 | (1) |
|
|
|
154 | (1) |
|
13.3 Looping through nodes |
|
|
155 | (1) |
|
13.4 JavaScript Object Notation - JSON |
|
|
156 | (1) |
|
|
|
156 | (1) |
|
13.6 Application Programming Interfaces |
|
|
157 | (2) |
|
13.7 Google geocoding web service |
|
|
159 | (2) |
|
13.8 Security and API usage |
|
|
161 | (4) |
|
|
|
165 | (1) |
|
|
|
165 | (2) |
| 14 Object-Oriented Programming |
|
167 | (14) |
|
14.1 Managing Larger Programs |
|
|
167 | (1) |
|
|
|
168 | (1) |
|
|
|
168 | (1) |
|
14.4 Starting with Programs |
|
|
169 | (2) |
|
14.5 Subdividing a Problem - Encapsulation |
|
|
171 | (1) |
|
14.6 Our First Python Object |
|
|
172 | (2) |
|
|
|
174 | (1) |
|
|
|
175 | (1) |
|
|
|
176 | (1) |
|
|
|
177 | (1) |
|
|
|
178 | (1) |
|
|
|
179 | (2) |
| 15 Using databases and SQL |
|
181 | (24) |
|
|
|
181 | (1) |
|
|
|
181 | (1) |
|
15.3 Database Browser for SQLite |
|
|
182 | (1) |
|
15.4 Creating a database table |
|
|
182 | (3) |
|
15.5 Structured Query Language summary |
|
|
185 | (2) |
|
15.6 Spidering Twitter using a database |
|
|
187 | (5) |
|
|
|
192 | (1) |
|
15.8 Programming with multiple tables |
|
|
193 | (3) |
|
15.8.1 Constraints in database tables |
|
|
196 | (1) |
|
15.8.2 Retrieve and/or insert a record |
|
|
197 | (1) |
|
15.8.3 Storing the friend relationship |
|
|
197 | (2) |
|
|
|
199 | (1) |
|
15.10 Using JOIN to retrieve data |
|
|
199 | (3) |
|
|
|
202 | (1) |
|
|
|
202 | (1) |
|
|
|
202 | (3) |
| 16 Visualizing data |
|
205 | (12) |
|
16.1 Building a Google map from geocoded data |
|
|
205 | (2) |
|
16.2 Visualizing networks and interconnections |
|
|
207 | (3) |
|
16.3 Visualizing mail data |
|
|
210 | (7) |
| A Contributions |
|
217 | (4) |
|
A.1 Contributor List for Python for Everybody |
|
|
217 | (1) |
|
A.2 Contributor List for Python for Informatics |
|
|
217 | (1) |
|
A.3 Preface for "Think Python" |
|
|
217 | (2) |
|
A.3.1 The strange history of "Think Python" |
|
|
217 | (2) |
|
A.3.2 Acknowledgements for "Think Python" |
|
|
219 | (1) |
|
A.4 Contributor List for "Think Python" |
|
|
219 | (2) |
| B Copyright Detail |
|
221 | |