# Print Debugging

> Adding lines that print values as the code runs. They show where it goes wrong.

**Field:** Software Development  
**Category:** Editors & Tools  
**Also known as:** Printf Debugging, Debug Print Statements, console.log Debugging

## Think of it like

It is like leaving notes on a trail. Each note says I was here, and this is what I saw.

## Definition

Print debugging is finding a bug by adding lines that print values while the program runs. You put a print line at each step you are unsure about. When you run the code, the lines show each value and the order the steps ran in. The first value that looks wrong points to the bug. Once the bug is fixed, you take the extra lines out again.

## 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.

## Example code

```python
price = read_price()
print("DEBUG price:", price)
total = price * qty
print("DEBUG total:", total)
```

Running it prints DEBUG price: 0, so the price is wrong before the total is worked out.

## Why it matters

It works in any language and on any machine. It even works where a debugger cannot reach.

## Common mistake

Forgetting to take the print lines out. They clutter the output, and they can leak private data into logs.

## Three principles

- **Print the values.** At each step you doubt.
- **Read the order.** The output shows what ran.
- **Clean up.** Delete the lines once it is fixed.

## Related terms

- [Debugging](https://learn.benibix.com/term/development/debugging)
- [Debugger](https://learn.benibix.com/term/development/debugger)
- [Breakpoint](https://learn.benibix.com/term/development/breakpoint)
- [Rubber Duck Debugging](https://learn.benibix.com/term/development/rubber-duck-debugging)
- [Bug](https://learn.benibix.com/term/development/bug)
- [Logging](https://learn.benibix.com/term/infrastructure/logging)

## Told apart from

- [Print Debugging vs Logging](https://learn.benibix.com/compare/print-debugging-vs-logging): People think print debugging is the same as logging, and it is not. Print lines are short-lived. You add them to chase one bug, then delete them. Logging stays in the code for good. It writes events with a time and a level, so people can read them long after the code ran.

## Taught in

- [Debuggers and Breakpoints](https://learn.benibix.com/learn/development-tools/debuggers-and-breakpoints): Coding Tools, 5/13

![Two panels on finding a bug without a debugger. Print debugging: four lines of code, two of them print lines that show the price and the total. Run it, and the output reads DEBUG price: 0, marked as the first wrong value, then DEBUG total: 0. The print lines come out again afterwards. Rubber duck debugging: three steps of a loop said out loud. Start at the first item, ok. Add each price, ok. Stop before length minus 1, marked skips one. A duck sits below and only listens.](https://learn.benibix.com/diagrams/left1-debugging.svg)

---

Source: https://learn.benibix.com/term/development/print-debugging
Author: Behnia Zarei (a developer in Vienna, Austria, who builds and teaches data, AI and business intelligence at BENIBIX)
Publisher: BENIBIX Learn (https://learn.benibix.com/)
Last updated: 2026-11-17
Licence: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Quote freely with attribution.
