The pdb module is used to debug Python programs. Python programs use pdb interactive source code debugger to debug the programs. pdb sets breakpoints and inspects the stack frames, and lists the source code.
Now we will learn about how we can use the pdb debugger. There are three ways to use this debugger:
- Within an interpreter
- From a command line
- Within a Python script
We are going to create a pdb_example.py script and add the following content in that script:
class Student:
def __init__(self, std):
self.count = std
def print_std(self):
for i in range(self.count):
print(i)
return
if __name__ == '__main__':
Student(5).print_std()
Using this script as an example to learn Python debugging, we will see how we can start the debugger in detail.