â– In addition to debugging by print statement, debugging by debugger is available.
â– The sample is debug.nurse3.
â– 1) To use the debugger, import pdb must be written before use.
â– 2) After 1), pdb.set_trace() statement or later is the target of debugging.
â– 3) After pdb.set_trace() is executed, it stops with the following statement.
â– 4) Breakpoints can be set at the time.
â– Breakpoints are toggle switches, and clicking again will release the breakpoint.
â– When stopped, a tooltip appears when the mouse is hovered near a variable.

import pdb


def factorial(n, sum=0):
    if n == 0:
        return sum

    
    sum += n
    print(sum)
    return factorial(n-1, sum)

pdb.set_trace()
factorial(5)




â– The following shows the state of stopping after solving and after set_trace().
â– Let’s try to place a breakpoint.




Click the Execute button.




Stopped at the breakpoint. Double-click on the variable to see the current value.




Right-click to bring up the menu.