How to Think Like a Computer Scientist
Allen B. Downey
Python#
Computer_Scientist#
data_structures#
OOP#
Python is an excellent way to get started in programming, and this clear, concise guide walks you through Python a step at a time—beginning with basic programming concepts before moving on to functions, data structures, and object-oriented design. This revised third edition reflects the growing role of large language models (LLMs) in programming and includes exercises on effective LLM prompts, testing code, and debugging skills.
With this popular hands-on guide at your side, you'll get:
Table of Contents
Chapter 1. Programming as a Way of Thinking
Chapter 2. Variables and Statements
Chapter 3. Functions
Chapter 4. Functions and Interfaces
Chapter 5. Conditionals and Recursion
Chapter 6. Return Values
Chapter 7. Iteration and Search
Chapter 8. Strings and Regular Expressions
Chapter 9. Lists
Chapter 10. Dictionaries
Chapter 11. Tuples
Chapter 12. Text Analysis and Generation
Chapter 13. Files and Databases
Chapter 14. Classes and Functions
Chapter 15. Classes and Methods
Chapter 16. Classes and Objects
Chapter 17. Inheritance
Chapter 18. Python Extras
Chapter 19. Final Thoughts
Who Is This Book For?
If you want to learn to program, you have come to the right place. Python is one of the best programming languages for beginners—and it is also one of the most in-demand skills.
You have also come at the right time, because learning to program now is probably easier than ever. With virtual assistants like ChatGPT, you don’t have to learn alone. Throughout this book, I’ll suggest ways you can use these tools to accelerate your learning.
This book is primarily for people who have never programmed before and people who have some experience in another programming language. If you have substantial experience in Python, you might find the first few chapters too slow.
One of the challenges of learning to program is that you have to learn two languages: one is the programming language itself; the other is the vocabulary we use to talk about programs. If you learn only the programming language, you are likely to have problems when you need to interpret an error message, read documentation, talk to another person, or use virtual assistants. If you have done some programming, but you have not also learned this second language, I hope you find this book helpful.
Goals of the Book
Writing this book, I tried to be careful with the vocabulary. I define each term when it first appears. And there is a glossary at the end of each chapter that reviews the terms that were introduced.
I also tried to be concise. The less mental effort it takes to read the book, the more capacity you will have for programming.
But you can’t learn to program just by reading a book—you have to practice. For that reason, this book includes exercises at the end of every chapter where you can practice what you have learned.
If you read carefully and work on exercises consistently, you will make progress. But I’ll warn you now—learning to program is not easy, and even for experienced programmers it can be frustrating. As we go, I will suggest strategies to help you write correct programs and fix incorrect ones.
Allen Downey is a Staff Producer at Brilliant and Professor Emeritus at Olin College of Engineering. He has taught computer science at Wellesley College, Colby College and U.C. Berkeley. He has a Ph.D. in Computer Science from U.C. Berkeley and a Master’s Degree from MIT.