Debugging means finding the difference between what the code does and what you expected it to do.
Good debugging starts with the exact error message, the line number, and the smallest input that reproduces the problem.
Use prints, assertions, and breakpoints to inspect values before changing code blindly.
A traceback shows the call path that led to the error. The most useful line is usually the last frame that points to your own file.
prices = ["10", "20", "free"]
for price in prices:
print("checking:", price)
print(int(price))
checking: 10
10
checking: 20
20
checking: free
ValueError: invalid literal for int() with base 10: 'free'
The print before conversion shows which value causes the failure.
breakpoint() pauses the program so you can inspect variables step by step in the debugger.
quantity = 3
price = "25"
breakpoint()
total = quantity * int(price)
print(total)
When run locally, breakpoint() opens the debugger before total is calculated.
0 of 2 checked
Try this next
0 of 3 completed
No. Small print checks are useful. Remove or replace them with logging when the code becomes a real program.
Use it when you need to inspect several variables or step through code locally.
Start from the last frame that points to your code, then use earlier frames only if the cause is not obvious.
Explore 500+ free tutorials across 20+ languages and frameworks.