breakpoint()
breakpoint(*args, **kwargs) None · Added in v3.7 · Updated March 13, 2026 · Built-in Functions The breakpoint() function pauses program execution and drops you into an interactive debugger. It was introduced in Python 3.7 as a standardized way to enter debugging mode, replacing the older pdb.set_trace() pattern that many developers used for years.
When breakpoint() is called, Python suspends execution and presents an interactive prompt where you can inspect variables, step through code, and diagnose issues in real-time. This makes it invaluable for tracking down bugs that are difficult to reproduce or understand from print statements alone.
Syntax
breakpoint(*args, **kwargs)
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
*args | any | — | Positional arguments passed to the debugger |
**kwargs | any | — | Keyword arguments passed to the debugger |
Examples
Basic usage
def divide(a, b):
breakpoint() # Execution pauses here
return a / b
result = divide(10, 0)
When breakpoint() is called, Python drops into the debugger:
> /tmp/example.py(3)divide()
-> return a / b
(Pdb) p a
10
(Pdb) p b
0
(Pdb) q
Using with variables
data = {"name": "Alice", "score": 95}
breakpoint()
print(data)
You can inspect variables directly in the debugger:
(Pdb) pp data
{'name': 'Alice', 'score': 95}
(Pdb) data['score'] += 5
(Pdb) c
Debugging a loop
for i in range(5):
print(f"Processing {i}")
if i == 2:
breakpoint() # Stop at iteration 2
Inspecting complex data structures
class User:
def __init__(self, name, email):
self.name = name
self.email = email
user = User("Alice", "alice@example.com")
breakpoint()
(Pdb) pp user.__dict__
{'name': 'Alice', 'email': 'alice@example.com'}
(Pdb) self.name
*** NameError: self is not defined
(Pdb) p user.name
'Alice'
Common Debugger Commands
When inside the debugger, these commands are available:
| Command | Shortcut | Description |
|---|---|---|
p expression | — | Print the value of an expression |
pp expression | — | Pretty-print the value |
n | Enter | Execute next line |
s | — | Step into function |
c | — | Continue execution |
l | — | List source code |
w | — | Show call stack |
u | — | Move up the stack |
d | — | Move down the stack |
q | — | Quit the debugger |
Customizing the Debugger
By default, breakpoint() uses pdb. You can change this by setting sys.breakpointhook():
import pdb
import sys
# Use ipdb instead of pdb
# import ipdb; sys.breakpointhook = ipdb.set_trace
# Or disable breakpoint entirely
# sys.breakpointhook = lambda *args: None
# Use a custom debugger
# def my_debugger(*args):
# import IPython.embed
# IPython.embed()
# sys.breakpointhook = my_debugger
Using ipdb for better debugging
import sys
# Install ipdb: pip install ipdb
import ipdb
sys.breakpointhook = ipdb.set_trace
ipdb provides IPython features like tab completion, syntax highlighting, and magic commands, making debugging more pleasant than the basic pdb interface.
Setting debugger via environment variable
You can also configure the debugger without code changes:
# Use ipdb
PYTHONBREAKPOINT=ipdb.set_trace python script.py
# Disable breakpoint entirely
PYTHONBREAKPOINT=0 python script.py
# Use custom debugger class
PYTHONBREAKPOINT=my_module.my_debugger python script.py
Errors
| Error | When it occurs |
|---|---|
BdbQuit | When you quit the debugger with q or quit |
ZeroDivisionError | The actual error that caused execution to reach breakpoint() |
When to Use breakpoint()
Use breakpoint() when:
- You need to inspect the state of variables at a specific point
- You want to step through code line by line
- Print statements aren’t revealing the root cause
- You’re dealing with complex control flow
Skip breakpoint() and use logging instead when:
- The issue is in production and you can’t pause execution
- You’re debugging asynchronous code that might hang the debugger
- You need to capture the flow over many iterations