Python – breakpoint()
pythondebug() function drops you into the debugger at the call site. Specifically, it calls sys.breakpointhook(), passing args and kws straight through.
In this tutorial, we shall learn how to use breakpoint(), to debug your Python application in the console.
Syntax – breakpoint()
The syntax of breakpoint() function is:
Example 1: breakpoint() function
In this example, we will call breakpoint() function at some point in our python program and see what happens.
a = 2 b = 3 if(a+b == 5): breakpoint() print('sum is 5')
The system enters Python debugging mode at the print() statement and you can check the variable values in console as shown below.
C:\workspace\python>python example.py > c:\workspace\python\example.py(6)<module>() -> print('sum is 5') (Pdb) +a 2 (Pdb) +b 3 (Pdb) a+b (Pdb) +a+b 5 (Pdb)
In this tutorial of Python Examples, we learned how to use breakpoint() function to debug your Python application.