Format Your Output Like Picasso
The problem...
You know how to print. You've been doing it since the first article.
But right now your output is raw. Basic. It gets the job done — nothing more.
There's a difference between code that prints and code that communicates.
The idea!
Python's print() is more powerful than it looks.
You control the format. You control the precision. You control how numbers and text appear together.
Quick recap
You've already seen the basics:
name = "Bull"
age = 25
print(f"My name is {name} and I am {age} years old.")
Good. Now let's go further.
Formatting floats
Raw floats are often too long or too imprecise.
price = 3.14159265
print(price) # 3.14159265 — too many decimals
print(f"{price:.2f}") # 3.14 — 2 decimal places
print(f"{price:.4f}") # 3.1416 — 4 decimal places
print(f"{price:.0f}") # 3 — no decimals
:.2f means: format as float with 2 decimal places.
Formatting integers
score = 1000000
print(f"{score}") # 1000000 — hard to read
print(f"{score:,}") # 1,000,000 — with thousands separator
print(f"{score:10}") # right-aligned in 10 characters
print(f"{score:<10}") # left-aligned in 10 characters
Combining numbers and text
name = "Bull"
score = 1547.891
rank = 3
print(f"Player: {name:<10} | Score: {score:>10.2f} | Rank: #{rank}")
Output → Player: Bull | Score: 1547.89 | Rank: #3
Aligned. Clean. Professional.
Going further — padding and alignment
print(f"{'Name':<10} {'Score':>10}")
print(f"{'Bull':<10} {1547.89:>10.2f}")
print(f"{'Horn':<10} {983.45:>10.2f}")
print(f"{'Red':<10} {2341.00:>10.2f}")
Output:
Name Score
Bull 1547.89
Horn 983.45
Red 2341.00
A clean table. No external libraries. Just f-strings.
Percentage formatting
ratio = 0.857
print(f"{ratio:.0%}") # 86%
print(f"{ratio:.1%}") # 85.7%
print(f"{ratio:.2%}") # 85.70%
What's really happening
Inside {} in an f-string, you can add a format spec after :.
It tells Python exactly how to display the value — width, alignment, precision, type.
The code doesn't change. The output does.
Heads up!
:.2f— float with 2 decimals:,— thousands separator:<10— left-aligned in 10 chars:>10— right-aligned in 10 chars:.1%— percentage with 1 decimal
The mindset shift
Stop thinking: "print() just shows values."
Start thinking: "print() is a canvas. Format it."
What you should understand now
- f-strings accept format specs after
:inside{} .2fcontrols float precision,adds thousands separator- Alignment and width make output readable
- Percentage formatting is built in