#285 Think Python
Book notes - Think Python, 2nd edition, by Allen B. Downey, published by O’Reilly.
Notes
Table of Contents - Highlights
Preface
- The Strange History of This Book
- Conventions Used in This Book
- Using Code Examples
- O’Reilly Online Learning
- How to Contact Us
- Acknowledgments
- Contributor List
- The Way of the Program
- What Is a Program?
- Running Python
- The First Program
- Arithmetic Operators
- Values and Types
- Formal and Natural Languages
- Debugging
- Glossary
- Exercises
- Variables, Expressions and Statements
- Assignment Statements
- Variable Names
- Expressions and Statements
- Script Mode
- Order of Operations
- String Operations
- Comments
- Debugging
- Glossary
- Exercises
- Functions
- Function Calls
- Math Functions
- Composition
- Adding New Functions
- Definitions and Uses
- Flow of Execution
- Parameters and Arguments
- Variables and Parameters Are Local
- Stack Diagrams
- Fruitful Functions and Void Functions
- Why Functions?
- Debugging
- Glossary
- Exercises
- Case Study: Interface Design
- The turtle Module
- Simple Repetition
- Exercises
- Encapsulation
- Generalization
- Interface Design
- Refactoring
- A Development Plan
- docstring
- Debugging
- Glossary
- Exercises
- Conditionals and Recursion
- Floor Division and Modulus
- Boolean Expressions
- Logical Operators
- Conditional Execution
- Alternative Execution
- Chained Conditionals
- Nested Conditionals
- Recursion
- Stack Diagrams for Recursive Functions
- Infinite Recursion
- Keyboard Input
- Debugging
- Glossary
- Exercises
- Fruitful Functions
- Return Values
- Incremental Development
- Composition
- Boolean Functions
- More Recursion
- Leap of Faith
- One More Example
- Checking Types
- Debugging
- Glossary
- Exercises
- Iteration
- Reassignment
- Updating Variables
- The while Statement
- break
- Square Roots
- Algorithms
- Debugging
- Glossary
- Exercises
- Strings
- A String Is a Sequence
- len
- Traversal with a for Loop
- String Slices
- Strings Are Immutable
- Searching
- Looping and Counting
- String Methods
- The in Operator
- String Comparison
- Debugging
- Glossary
- Exercises
- Case Study: Word Play
- Reading Word Lists
- Exercises
- Search
- Looping with Indices
- Debugging
- Glossary
- Exercises
- Lists
- A List Is a Sequence
- Lists Are Mutable
- Traversing a List
- List Operations
- List Slices
- List Methods
- Map, Filter and Reduce
- Deleting Elements
- Lists and Strings
- Objects and Values
- Aliasing
- List Arguments
- Debugging
- Glossary
- Exercises
- Dictionaries
- A Dictionary Is a Mapping
- Dictionary as a Collection of Counters
- Looping and Dictionaries
- Reverse Lookup
- Dictionaries and Lists
- Memos
- Global Variables
- Debugging
- Glossary
- Exercises
- Tuples
- Tuples Are Immutable
- Tuple Assignment
- Tuples as Return Values
- Variable-Length Argument Tuples
- Lists and Tuples
- Dictionaries and Tuples
- Sequences of Sequences
- Debugging
- Glossary
- Exercises
- Case Study: Data Structure Selection
- Word Frequency Analysis
- Random Numbers
- Word Histogram
- Most Common Words
- Optional Parameters
- Dictionary Subtraction
- Random Words
- Markov Analysis
- Data Structures
- Debugging
- Glossary
- Exercises
- Files
- Persistence
- Reading and Writing
- Format Operator
- Filenames and Paths
- Catching Exceptions
- Databases
- Pickling
- Pipes
- Writing Modules
- Debugging
- Glossary
- Exercises
- Classes and Objects
- Programmer-Defined Types
- Attributes
- Rectangles
- Instances as Return Values
- Objects Are Mutable
- Copying
- Debugging
- Glossary
- Exercises
- Classes and Functions
- Time
- Pure Functions
- Modifiers
- Prototyping versus Planning
- Debugging
- Glossary
- Exercises
- Classes and Methods
- Object-Oriented Features
- Printing Objects
- Another Example
- A More Complicated Example
- The init Method
- The str Method
- Operator Overloading
- Type-Based Dispatch
- Polymorphism
- Interface and Implementation
- Debugging
- Glossary
- Exercises
- Inheritance
- Card Objects
- Class Attributes
- Comparing Cards
- Decks
- Printing the Deck
- Add, Remove, Shuffle and Sort
- Inheritance
- Class Diagrams
- Data Encapsulation
- Debugging
- Glossary
- Exercises
- The Goodies
- Conditional Expressions
- List Comprehensions
- Generator Expressions
- any and all
- Sets
- Counters
- defaultdict
- Named Tuples
- Gathering Keyword Args
- Glossary
- Exercises
- Debugging
- Syntax Errors
- I keep making changes and it makes no difference.
- Runtime Errors
- My program does absolutely nothing.
- My program hangs.
- When I run the program I get an exception.
- I added so many print statements I get inundated with output.
- Semantic Errors
- My program doesn’t work.
- I’ve got a big hairy expression and it doesn’t do what I expect.
- I’ve got a function that doesn’t return what I expect.
- I’m really, really stuck and I need help.
- No, I really need help.
- Analysis of Algorithms
- Order of Growth
- Analysis of Basic Python Operations
- Analysis of Search Algorithms
- Hashtables
Getting the Example Source
git clone https://github.com/AllenDowney/ThinkPython2.git example_source
Credits and References
- Think Python, 2nd Edition
- Errata
- Think Python, 2nd edition - greenteapress
- example code
- Think Python - GoodReads