Put one = inside an f-string: f"{total=}" prints total=550. It also works with expressions and formats, like len(rows)=3 and rate=12.5% (Python 3.8+).
python3 --version.python3 -m venv .venv source .venv/bin/activate
python3 debug.py
rows = [120, 340, 90]
total = sum(rows)
rate = total / 4400
print(total)
print(f"{total=}")
print(f"{len(rows)=} {rate=:.1%}")Stop printing bare variables. Which number is that? Add an equals sign in the f-string, and you get the name and value. Expressions and format specs work too.
Total equals 550. Rate, 12.5 percent. Needs Python 3.
8. Name your prints.
Read the lesson on GitHub →