Conclusion

Errors are messages about broken assumptions.

In this chapter, you learned how to read those messages without panic. You read tracebacks from the bottom, separated syntax errors from runtime errors, recognized common name, type, and index failures, used assertions to state assumptions, and reduced failing programs until the cause became visible.

This is the debugging loop:

  1. Read the error type and message.
  2. Find the failing line.
  3. Name the assumption.
  4. Inspect the smallest useful value.
  5. Change one thing.
  6. Run again.

That loop is more important than memorizing exception names.

The assertion does not make the function complete. It makes one assumption visible. That is often enough to prevent a vague failure later.

What comes next

The next chapter introduces files, paths, and modules.

Debugging becomes even more useful there because programs start to depend on things outside one file: filenames, directories, imports, and small reusable modules. The habits from this chapter help you locate whether the problem is in your code, your data, or the path between them.