Python breakpoint() built-in function

From the Python 3 documentation

This function drops you into the debugger at the call site [...].
Python breakpoint() calls Python debugger at a given line

Introduction

The breakpoint() function in Python, introduced in Python 3.7, provides an easy way to enter the Python debugger (pdb) at a specific point in your code. It’s a convenient alternative to manually importing pdb and calling pdb.set_trace(). This function simplifies the debugging process, allowing you to inspect variables and step through your code interactively.

Example

Here’s how you can use breakpoint() to pause execution and inspect variables:

def calculate_sum(a, b):
    result = a + b
    # We want to inspect the 'result' before returning
    breakpoint()
    return result

# When you run this, the debugger will start right after 'result' is calculated
# You can then type 'result' in the (Pdb) prompt to see its value
# To continue execution, type 'c' or 'continue'
final_sum = calculate_sum(10, 20)
print(final_sum)

# (Pdb) result
# 30
# (Pdb) c
# 30

Subscribe to pythoncheatsheet.org

Join 16,702+ Python developers in a two times a month and bullshit free publication , full of interesting, relevant links.