Skip to content

traceback

A traceback is the structured sequence of function calls that Python records when an exception is raised. The Python interpreter prints it automatically when the exception goes unhandled, and you can extract, format, or print it yourself with the traceback module.

The traceback details the path your code took right before crashing, pointing you to the exact filename, line number, and the type of error encountered. Since Python 3.11, the interpreter also underlines the exact expression that raised the error with ~ and ^ markers, like the ~~^~~ beneath a / b below.

Language: Python Traceback
Traceback (most recent call last):
  File "example.py", line 4, in <module>
    result = divide(10, 0)
  File "example.py", line 2, in divide
    return a / b
           ~~^~~
ZeroDivisionError: division by zero

Reading tracebacks is essential for debugging Python code. It lets you pinpoint the origin of the error and see how different functions relate in the call chain, so you can fix issues more quickly.

Understanding the Python Traceback

Tutorial

Understanding the Python Traceback

In this step-by-step tutorial, you'll learn how to read and understand the information you can get from a Python traceback. You'll walk through several examples of tracebacks and see some of the most common tracebacks in Python.

basics python

For additional information on related topics, take a look at the following resources:

Have a question about this? Mentor AI can show you examples, compare related terms, and point you to tutorials.


By Dan Bader • Updated Sept. 21, 2026