🛠️Print Debugging
Also known as Printf Debugging, Debug Print Statements, console.log Debugging
Adding lines that print values as the code runs. They show where it goes wrong.
Think of it like
It is like leaving notes on a trail. Each note says I was here, and this is what I saw.
Example
Jack's shopping cart always shows a total of 0. He adds a print line before and after the sum. The first one already prints a price of 0, so the bug is where the price is read in.
Why it matters
Definition
Example code
python
price = read_price()
print("DEBUG price:", price)
total = price * qty
print("DEBUG total:", total)Common mistake
Key takeaways
- 1Print the values. At each step you doubt.
- 2Read the order. The output shows what ran.
- 3Clean up. Delete the lines once it is fixed.