Read Python Like a Pro / Errors and help
Lesson 8 of 10
Using print to debug
When code does something odd, print the variables just before the problem. f-strings with = show the name and value together.
Key points
- print(f"{x=}") shows x=5
- Print inside loops to watch changes
- Remove debug prints when you're done
price = 20
discount = 0.25
final = price - price * discount
print(f"{price=} {discount=} {final=}")Your turn
Add f"{...=}" debug prints inside a loop you wrote earlier and watch the values change.
Quiz · +10 XP
What does f"{x=}" print when x is 5?
Log in to save progress and earn XP.