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.
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.
Related Resources
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.
For additional information on related topics, take a look at the following resources:
- Python Exceptions: An Introduction (Tutorial)
- Python's Built-in Exceptions: A Walkthrough With Examples (Tutorial)
- Getting the Most Out of a Python Traceback (Course)
- How to Debug Common Python Errors (Tutorial)
- Python's raise: Effectively Raising Exceptions in Your Code (Tutorial)
- Understanding the Python Traceback (Quiz)
- Introduction to Python Exceptions (Course)
- Raising and Handling Python Exceptions (Course)
- Python Exceptions: An Introduction (Quiz)
- Working With Python's Built-in Exceptions (Course)
- Python's Built-in Exceptions: A Walkthrough With Examples (Quiz)
- How to Debug Common Python Errors (Quiz)
- Using raise for Effective Exceptions (Course)
- Python's raise: Effectively Raising Exceptions in Your Code (Quiz)
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