Summary
Sooner or later, your code will do things you don’t expect. Probably sooner. This chapter was about what to do when that happens. Debugging is the process of identifying, analyzing, and fixing problems in code. We looked at different types of bugs and ways to deal with them.
Syntax and runtime errors come with helpful error messages. If you can read a traceback (and don’t get too intimidated by the red letters), Python is often telling you exactly what went wrong.
Logical bugs are trickier. That’s when your code runs without errors but still doesn’t behave as you intended. It’s this detective work that makes debugging fun. Sometimes a simple cup of coffee is all it takes to spot the issue. But when that doesn’t help, print statements can come to the rescue. They may be frowned upon, but they work. If you want more control, a lot of IDEs (including VS Code) also have a built-in debugger. That’s where the little red dot...