← Back to Blog

Your Output, Your Rules

The problem...

You know how to print. But right now, your output looks raw.

No formatting. No structure. Just text thrown on the screen.

That's fine for learning. But there's a better way.

The idea!

Python gives you tools to control exactly how your output looks.

Same data. Cleaner result.

Making it real

You've been using print() like this:

name = "Bull"
print("Hello", name)

Output → Hello Bull

It works. But you have more control than that.

sep — what goes between values

By default, print() puts a space between values. You can change that.

print("Red", "Horn", "Dev", sep="-")

Output → Red-Horn-Dev

print("Red", "Horn", "Dev", sep="")

Output → RedHornDev

end — what goes at the end

By default, print() adds a new line at the end. You can change that too.

print("Hello", end=" ")
print("Bull")

Output → Hello Bull

Both prints end up on the same line.

In practice

f-strings are the cleanest way to mix variables and text.

name = "Bull"
age = 25
print(f"My name is {name} and I am {age} years old.")

Output → My name is Bull and I am 25 years old.

Put an f before the quote. Use {} to insert any variable directly.

Going further

f-strings can do more than just insert values. They can format them too.

price = 3.14159
print(f"Price: {price:.2f}")

Output → Price: 3.14

:.2f means: show this number with 2 decimal places.

What's really happening

You're not just printing. You're constructing output — deciding what goes where, how it looks, and how it reads.

That's the difference between code that works and code that communicates.

Heads up!

  • The f before the quote is not optional — without it, {name} prints literally
  • sep and end only work inside print()
  • f-strings are the modern way — you might see .format() in older code, but f-strings are cleaner

The mindset shift

Stop thinking: "I just need to print something."

Start thinking: "I control exactly what my output looks like."

What you should understand now

  • sep controls what goes between values in print()
  • end controls what goes at the end of a line
  • f-strings let you insert variables directly into text
  • f-strings can also format numbers and other values
[ login to bookmark ] // copied! 47 views · 1 min
// resources
Code Example print_formatting.py
← prev Working With What’s Inside Strings next → Your Program Is Listening
// 0 comments
// No comments yet. Be the first.
// leave a comment

// Your comment will appear after approval.