Think Python

June 2008: major revision, changed title suggests Python: how to think like … How to think like a computer scientist: Learning with Python, also under the ….

More PDF Content

Think Python
1 The way of the program
1.1 The Python programming language …
1.2 What is a program? …
1.3 What is debugging? …
1.4 Formal and natural languages …
1.5 The first program …
1.6 Debugging …
1.7 Glossary …
1.8 Exercises …
2 Variables, expressions and statements
2.1 Values and types …
2.2 Variables …
2.3 Variable names and keywords …
2.4 Statements …
2.5 Operators and operands …
2.6 Expressions …
2.7 Order of operations …
2.8 String operations …
2.9 Comments …
2.10 Debugging …
2.11 Glossary …
2.12 Exercises …
3 Functions
3.1 Function calls …
3.2 Type conversion functions …
3.3 Math functions …
3.4 Composition …
3.5 Adding new functions …
3.6 Definitions and uses …
3.7 Flow of execution …
3.8 Parameters and arguments …
3.9 Variables and parameters are local …
3.10 Stack diagrams …
3.11 Fruitful functions and void functions …
3.12 Why functions? …
3.13 Debugging …
3.14 Glossary …
3.15 Exercises …
4 Case study: interface design
4.1 TurtleWorld …
4.2 Simple repetition …
4.3 Exercises …
4.4 Encapsulation …
4.5 Generalization …
4.6 Interface design …
4.7 Refactoring …
4.8 A development plan …
4.9 docstring …
4.10 Debugging …
4.11 Glossary …
4.12 Exercises …
5 Conditionals and recursion
5.1 Modulus operator …
5.2 Boolean expressions …
5.3 Logical operators …
5.4 Conditional execution …
5.5 Alternative execution …
5.6 Chained conditionals …
5.7 Nested conditionals …
5.8 Recursion …
5.9 Stack diagrams for recursive functions …
5.10 Infinite recursion …
5.11 Keyboard input …
5.12 Debugging …
5.13 Glossary …
5.14 Exercises …
6 Fruitful functions
6.1 Return values …
6.2 Incremental development …
6.3 Composition …
6.4 Boolean functions …
6.5 More recursion …
6.6 Leap of faith …
6.7 One more example …
6.8 Checking types …
6.9 Debugging …
6.10 Glossary …
6.11 Exercises …
7 Iteration
7.1 Multiple assignment …
7.2 Updating variables …
7.3 The while statement …
7.4 break …
7.5 Square roots …
7.6 Algorithms …
7.7 Debugging …
7.8 Glossary …
7.9 Exercises …
8 Strings
8.1 A string is a sequence …
8.2 len …
8.3 Traversal with a for loop …
8.4 String slices …
8.5 Strings are immutable …
8.6 Searching …
8.7 Looping and counting …
8.8 string methods …
8.9 The in operator …
8.10 String comparison …
8.11 Debugging …
8.12 Glossary …
8.13 Exercises …
9 Case study: word play
9.1 Reading word lists …
9.2 Exercises …
9.3 Search …
9.4 Looping with indices …
9.5 Debugging …
9.6 Glossary …
9.7 Exercises …
10 Lists
10.1 A list is a sequence …
10.2 Lists are mutable …
10.3 Traversing a list …
10.4 List operations …
10.5 List slices …
10.6 List methods …
10.7 Map, filter and reduce …
10.8 Deleting elements …
10.9 Lists and strings …
10.10 Objects and values …
10.11 Aliasing …
10.12 List arguments …
10.13 Debugging …
10.14 Glossary …
10.15 Exercises … 100
11 Dictionaries
11.1 Dictionary as a set of counters … 104
11.2 Looping and dictionaries … 106
11.3 Reverse lookup … 106
11.4 Dictionaries and lists … 107
11.5 Memos
11.6 Global variables … 110
11.7 Long integers … 111
11.8 Debugging … 112
11.9 Glossary … 112
11.10 Exercises … 113
12 Tuples
12.1 Tuples are immutable … 115
12.2 Tuple assignment … 116
12.3 Tuples as return values … 117
12.4 Variable-length argument tuples … 117
12.5 Lists and tuples … 118
12.6 Dictionaries and tuples … 119
12.7 Comparing tuples … 121
12.8 Sequences of sequences … 121
2.9 Debugging … 122
12.10 Glossary … 123
12.11 Exercises … 123
13 Case study: data structure selection
13.1 Word frequency analysis … 125
13.2 Random numbers … 126
13.3 Word histogram … 127
13.4 Most common words … 128
13.5 Optional parameters … 128
13.6 Dictionary subtraction … 129
13.7 Random words … 129
13.8 Markov analysis … 130
13.9 Data structures … 131
13.10 Debugging … 132
13.11 Glossary … 133
13.12 Exercises … 134
14 Files
14.1 Persistence … 135
14. Reading and writing … 135
14.3 Format operator … 136
14.4 Filenames and paths … 137
14.5 Catching exceptions … 138
14.6 Databases … 139
14.7 Pickling … 139
14.8 Pipes … 140
14.9 Writing modules
14.10 Debugging … 142
14.11 Glossary … 143
14.12 Exercises … 143
15 Classes and objects
15.1 User-defined types … 145
15.2 Attributes … 146
15.3 Rectangles … 147
15.4 Instances as return values … 148
15.5 Objects are mutable … 148
15.6 Copying … 149
15.7 Debugging … 150
15.8 Glossary … 151
15.9 Exercises … 151
16 Classes and functions
16.1 Time … 153
16.2 Pure functions … 154
16.3 Modifiers … 155
16.4 Prototyping versus planning … 156
16.5 Debugging … 157
16.6 Glossary … 158
16.7 Exercises … 158
17 Classes and methods
17.1 Object-oriented features … 159
17.2 Printing objects … 160
17.3 Another example … 161
17.4 A more complicated example … 162
17.5 The init method … 162
17.6 The str method … 163
17.7 Operator overloading … 163
17.8 Type-based dispatch … 164
17.9 Polymorphism … 165
17.10 Debugging … 166
17.11 Glossary … 166
17.12 Exercises … 167
18 Inheritance
18.1 Card objects … 169
18.2 Class attributes … 170
18.3 Comparing cards … 171
18.4 Decks … 172
18.5 Printing the deck … 172
18.6 Add, remove, shuffle and sort … 173
18.7 Inheritance … 174
18.8 Class diagrams … 175
18.9 Debugging … 176
18.10 Glossary … 177
18.11 Exercises … 178
19 Case study: Tkinter
19.1 GUI … 181
19.2 Buttons and callbacks … 182
19.3 Canvas widgets … 183
19.4 Coordinate sequences … 184
19.5 More widgets … 184
19.6 Packing widgets … 185
19.7 Menus and Callables … 188
19.8 Binding … 189
19.9 Debugging … 191
19.10 Glossary … 191
19.11 Exercises … 192
A Debugging
A.1 Syntax errors … 195
A.2 Runtime errors … 197
A.3 antic errors … 199

Download Think Python pdf from greenteapress.com, 234 pages, 1066.03KB.