Introductory programming education aims to develop computational thinking alongside coding skills that can be applied in academic and professional settings. Python is widely used in teaching because its clear syntax allows beginners to focus on core concepts such as variables, control flow, data structures, and abstraction without being distracted by low-level technical details. A structured introduction to programming with Python provides a solid foundation for further study in computer science and software development.
About the book
How to Think Like a Computer Scientist: Learning with Python by Allen Downey, Jeffrey Elkner, and Chris Meyers is an introductory computer science textbook that teaches programming through Python. The book centers on the reasoning processes involved in problem solving and program design, rather than limiting itself to language syntax.
It is intended for first-year computer science students and beginners with no prior programming experience. The material advances from fundamental ideas—such as what a program is and how debugging works—to topics including object-oriented programming and abstract data types. The text supports both procedural and object-oriented programming and includes discussions of debugging, recursion, data structures, and algorithmic reasoning.
The book is released under the GNU Free Documentation License, allowing readers to copy, distribute, and modify the text under the terms specified in the license.
What you will learn
Readers learn how to write, read, and analyze Python programs from the ground up. The book introduces essential constructs such as variables, expressions, conditionals, functions, iteration, and input handling. It then expands into compound data types including strings, lists, tuples, and dictionaries.
As the material advances, the book covers file handling, exceptions, and object-oriented programming concepts such as classes, objects, methods, inheritance, and polymorphism. It also presents core data structures and abstract data types, including linked lists, stacks, queues, and trees.
Throughout the chapters, the emphasis remains on problem solving, understanding program execution, managing complexity through abstraction and generalization, and developing debugging strategies. By the end of the book, readers gain a structured understanding of foundational computer science concepts implemented in Python.
Table of contents
- Foreword
Preface
Contributor List - 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 Glossary - 2 Variables, expressions and statements
2.1 Values and types
2.2 Variables
2.3 Variable names and keywords
2.4 Statements
2.5 Evaluating expressions
2.6 Operators and operands
2.7 Order of operations
2.8 Operations on strings
2.9 Composition
2.10 Comments
2.11 Glossary - 3 Functions
3.1 Function calls
3.2 Type conversion
3.3 Type coercion
3.4 Math functions
3.5 Composition
3.6 Adding new functions
3.7 Definitions and use
3.8 Flow of execution
3.9 Parameters and arguments
3.10 Variables and parameters are local
3.11 Stack diagrams
3.12 Functions with results
3.13 Glossary - 4 Conditionals and recursion
4.1 The modulus operator
4.2 Boolean expressions
4.3 Logical operators
4.4 Conditional execution
4.5 Alternative execution
4.6 Chained conditionals
4.7 Nested conditionals
4.8 The return statement
4.9 Recursion
4.10 Stack diagrams for recursive functions
4.11 Infinite recursion
4.12 Keyboard input
4.13 Glossary - 5 Fruitful functions
5.1 Return values
5.2 Program development
5.3 Composition
5.4 Boolean functions
5.5 More recursion
5.6 Leap of faith
5.7 One more example
5.8 Checking types
5.9 Glossary - 6 Iteration
6.1 Multiple assignment
6.2 The while statement
6.3 Tables
6.4 Two-dimensional tables
6.5 Encapsulation and generalization
6.6 More encapsulation
6.7 Local variables
6.8 More generalization
6.9 Functions
6.10 Glossary - 7 Strings
7.1 A compound data type
7.2 Length
7.3 Traversal and the for loop
7.4 String slices
7.5 String comparison
7.6 Strings are immutable
7.7 A find function
7.8 Looping and counting
7.9 The string module
7.10 Character classification
7.11 Glossary - 8 Lists
8.1 List values
8.2 Accessing elements
8.3 List length
8.4 List membership
8.5 Lists and for loops
8.6 List operations
8.7 List slices
8.8 Lists are mutable
8.9 List deletion
8.10 Objects and values
8.11 Aliasing
8.12 Cloning lists
8.13 List parameters
8.14 Nested lists
8.15 Matrices
8.16 Strings and lists
8.17 Glossary - 9 Tuples
9.1 Mutability and tuples
9.2 Tuple assignment
9.3 Tuples as return values
9.4 Random numbers
9.5 List of random numbers
9.6 Counting
9.7 Many buckets
9.8 A single-pass solution
9.9 Glossary - 10 Dictionaries
10.1 Dictionary operations
10.2 Dictionary methods
10.3 Aliasing and copying
10.4 Sparse matrices
10.5 Hints
10.6 Long integers
10.7 Counting letters
10.8 Glossary - 11 Files and exceptions
11.1 Text files
11.2 Writing variables
11.3 Directories
11.4 Pickling
11.5 Exceptions
11.6 Glossary - 12 Classes and objects
12.1 User-defined compound types
12.2 Attributes
12.3 Instances as arguments
12.4 Sameness
12.5 Rectangles
12.6 Instances as return values
12.7 Objects are mutable
12.8 Copying
12.9 Glossary - 13 Classes and functions
13.1 Time
13.2 Pure functions
13.3 Modifiers
13.4 Which is better?
13.5 Prototype development versus planning
13.6 Generalization
13.7 Algorithms
13.8 Glossary - 14 Classes and methods
14.1 Object-oriented features
14.2 printTime
14.3 Another example
14.4 A more complicated example
14.5 Optional arguments
14.6 The initialization method
14.7 Points revisited
14.8 Operator overloading
14.9 Polymorphism
14.10 Glossary - 15 Sets of objects
15.1 Composition
15.2 Card objects
15.3 Class attributes and the str method
15.4 Comparing cards
15.5 Decks
15.6 Printing the deck
15.7 Shuffling the deck
15.8 Removing and dealing cards
15.9 Glossary - 16 Inheritance
16.1 Inheritance
16.2 A hand of cards
16.3 Dealing cards
16.4 Printing a Hand
16.5 The CardGame class
16.6 OldMaidHand class
16.7 OldMaidGame class
16.8 Glossary - 17 Linked lists
17.1 Embedded references
17.2 The Node class
17.3 Lists as collections
17.4 Lists and recursion
17.5 Infinite lists
17.6 The fundamental ambiguity theorem
17.7 Modifying lists
17.8 Wrappers and helpers
17.9 The LinkedList class
17.10 Invariants
17.11 Glossary - 18 Stacks
18.1 Abstract data types
18.2 The Stack ADT
18.3 Implementing stacks with Python lists
18.4 Pushing and popping
18.5 Using a stack to evaluate postfix
18.6 Parsing
18.7 Evaluating postfix
18.8 Clients and providers
18.9 Glossary - 19 Queues
19.1 The Queue ADT
19.2 Linked Queue
19.3 Performance characteristics
19.4 Improved Linked Queue
19.5 Priority queue
19.6 The Golfer class
19.7 Glossary - 20 Trees
20.1 Building trees
20.2 Traversing trees
20.3 Expression trees
20.4 Tree traversal
20.5 Building an expression tree
20.6 Handling errors
20.7 The animal tree
20.8 Glossary - A Debugging
A.1 Syntax errors
A.2 Runtime errors
A.3 Semantic errors - B Creating a new data type
B.1 Fraction multiplication
B.2 Fraction addition
B.3 Euclid’s algorithm
B.4 Comparing fractions
B.5 Taking it further
B.6 Glossary - C Recommendations for further reading
C.1 Python-related web sites and books
C.2 Recommended general computer science books - D GNU Free Documentation License
Book details
- Title: How to Think Like a Computer Scientist: Learning with Python
- Author(s): Allen Downey; Jeffrey Elkner; Chris Meyers
- Main category: Programming
- Subcategory: Python
- Language: English
- License: GNU Free Documentation License, Version 1.1 or any later version published by the Free Software Foundation
More books in: Programming, Python
Legal notice: This book is shared for educational purposes only. The content is distributed under Creative Commons licenses or with explicit permission from the author. FreeProgrammingBooks may host files that comply with their respective licenses.