You can order print and ebook versions of Think Python 3e from Bookshop.org and Amazon.

Preface#

Who Is This Book For?#

If you want to learn to program, you have come to the right place. Moonli is one of the best programming languages for beginners – and it is also one of the most in-demand skills.

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 or Julia or similar languages, 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 that 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.

Getting started#

For most programming languages, including Moonli, there are many tools you can use to write and run programs. These tools are called integrated development environments (IDEs). In general, there are several kinds of IDEs:

  1. The most basic is a REPL. We will get into what it means in a moment. But essentially, a REPL provides a way to chat with the development environment in the language that the development environment is meant for.

  2. However, REPLs do not have memory. Once the REPL is closed, the code is lost. To avoid this, you can write code in files. Most programming languages these days work with files that contain code. So they provide tools for editing and running these files.

  3. Others work primarily with notebooks, which are documents that contain text and code.

  4. However, while files make it easy to run and understand code from start to end, notebooks make it difficult to understand which order to run the code in, the next time you open the notebook. A few languages (Smalltalk, Common Lisp) work with what are termed “images”. These provide the best of both worlds: You write code in one or more files. You send small parts of the files to the REPL. The REPL responds to your code and produces output. You can load the file into the REPL and make sure that running it from top to bottom produces the correct results.

For beginners, I recommend starting with a REPL that comes with the Moonli binaries. These are available from digikar99/moonli.

Acknowledgments#

Full acknowledgements to Allen Downey and the contributors of Think Python who have made it available under Creative Commons license enable free modification and distribution (for non-commercial purposes).

Many thanks to Jeff Elkner, who translated my Java book into Python, which got this project started and introduced me to what has turned out to be my favorite language. Thanks also to Chris Meyers, who contributed several sections to How to Think Like a Computer Scientist.

Thanks to the Free Software Foundation for developing the GNU Free Documentation License, which helped make my collaboration with Jeff and Chris possible, and thanks to the Creative Commons for the license I am using now.

Thanks to the developers and maintainers of the Python language and the libraries I used, including the Turtle graphics module; the tools I used to develop the book, including Jupyter and JupyterBook; and the services I used, including ChatGPT, Copilot, Colab and GitHub.

Thanks to the editors at Lulu who worked on How to Think Like a Computer Scientist and the editors at O’Reilly Media who worked on Think Python.

Special thanks to the technical reviewers for the second edition, Melissa Lewis and Luciano Ramalho, and for the third edition, Sam Lau and Luciano Ramalho (again!). I am also grateful to Luciano for developing the turtle graphics module I use in several chapters, called jupyturtle.

Thanks to all the students who worked with earlier versions of this book and all the contributors who sent in corrections and suggestions. More than 100 sharp-eyed and thoughtful readers have sent in suggestions and corrections over the past few years. Their contributions, and enthusiasm for this project, have been a huge help.

If you have a suggestion or correction, please send email to feedback@thinkpython.com. If you include at least part of the sentence the error appears in, that makes it easy for me to search. Page and section numbers are fine, too, but not quite as easy to work with. Thanks!

Think Moonli

Copyright 2024 Allen B. Downey

Code license: MIT License

Text license: Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International