How does the built-in `breakpoint()` function help debug Python code interactively, and what does it do by default?
Answer
Calling `breakpoint()` anywhere in code (introduced by PEP 553 in Python 3.7) pauses execution at that exact line and drops into `pdb`, the standard-library interactive debugger, letting you inspect local variables, evaluate expressions, and step through subsequent lines one at a time from a prompt right where the program stopped. It respects the `PYTHONBREAKPOINT` environment variable, so teams can redirect it to a different debugger (like `ipdb` or a remote debugger) globally, or disable it entirely in production (`PYTHONBREAKPOINT=0`), without editing a single line of source code.
Strong answer includes
- pauses execution at that line and drops into pdb by default
- lets you inspect locals, evaluate expressions, and step through code
- PYTHONBREAKPOINT env var can redirect or disable it without code changes
Practical example
Adding
breakpoint()right before a failing calculation drops into an interactive
(Pdb)prompt at that exact point, where typing `p variable_name` shows its current value without adding any temporary
print()statements.