The breakpoint()
function is a new debugging tool introduced in Python 3.7. It's a built-in function that inserts a breakpoint during program execution, pausing the program at that point for further debugger commands.
Calling the breakpoint()
function in your code will make the Python interpreter pause execution and enter debugger mode at the calling location. At this point, you can inspect the program state, examine variable values, step through execution, and more.
breakpoint()
is equivalent to:
import pdb
pdb.set_trace()
The following code demonstrates using the breakpoint()
function to insert a breakpoint:
def func(a, b):
c = a + b
breakpoint() # Insert a breakpoint here
return c
result = func(2, 3)
print(result)
When execution reaches breakpoint()
, the program will pause and enter debugger mode at that location. You can then enter commands to inspect variable values, execute code, or continue debugging. When finished debugging, you can enter the continue
command to resume program execution.