DEV Community

qing
qing

Posted on

Quick Tip: Use `breakpoint()` instead of `import pdb; pdb.set_trace()` (2026)

Quick Tip: Use breakpoint() instead of import pdb; pdb.set_trace()

When debugging Python code, it's common to use the pdb module to set breakpoints and inspect variables. However, since Python 3.7, there's a more convenient way to do this. Say goodbye to import pdb; pdb.set_trace() and hello to the built-in breakpoint() function.

breakpoint() is a shortcut that allows you to set a breakpoint in your code without having to import the pdb module. When called, it will drop you into a debugger at that point in your code, allowing you to inspect variables, step through code, and more.

Using breakpoint() is as simple as adding the function


Follow me on Dev.to for daily Python tips and quick guides!


喜欢这篇文章?关注获取更多Python自动化内容!

Top comments (0)