23. Using Breakpoint
Python 3.7+ introduces the breakpoint() function as a shortcut to enter the debugger.
Example
x = 42
breakpoint()
print(x)
This behaves like calling pdb.set_trace() but respects the PYTHONBREAKPOINT environment variable.
Why Use breakpoint()?
- Cleaner and more explicit than importing pdb manually.
- Can be customized with
PYTHONBREAKPOINTto use other debuggers.
Practice Challenge
Insert a breakpoint() into a function that calculates Fibonacci numbers and step through execution.
Wrap-Up
Use breakpoint() for quick, modern debugging in Python 3.7+.