CurriculumPython print() for KidsBuilding output

Python f-strings vs .format() vs + for Building Output

f-strings, .format(), and + — and why + between text and a number crashes.

Lesson 5 of 5FreeAges 10+
Try this lesson interactively →

Building output

You already know a comma inside print() joins words and numbers with a space between. Let's look at three more ways to build a line — and one crash worth understanding.

First, a fact you already know, explained properly: every print() call ends with a hidden newline — that IS the end setting you met before, just left at its default.

print("first")
print("second")

Output

first
second

print's end defaults to "\n" — a newline character — even when you never type it. That's the whole reason two prints land on two lines: each one signs off with its own line break.

print("first", end="\n")
print("second", end="\n")

Output

first
second

Now the crash. You've joined text and numbers with a comma before. Try joining them with + instead, and Python refuses.

print("Gold: " + 50)

That raises a TypeError: can only concatenate str (not "int") to str. + glues text to text — it has no idea how to glue text to a number.

The fix: str() turns a number into text, so + has two strings to glue.

print("Gold: " + str(50))

Output

Gold: 50

There's a cleaner way that skips the problem entirely: an f-string. Put f before the quotes, and anything inside {} gets swapped in automatically — numbers included.

gold = 50
print(f"Gold: {gold}")

Output

Gold: 50

f-strings never raise that TypeError, because the {} does the str() conversion for you, silently.

print(f"Total: {50}")

Output

Total: 50

One more tool you'll see in other people's code: .format(). {} marks the gaps, and .format() fills them in order.

print("Gold: {}".format(50))

Output

Gold: 50

Four tools, one job: comma, +, f-string, .format(). The comma and f-string are what you'll reach for most — + needs str() by hand, and .format() you'll mostly just recognise.

Check your understanding

Why do print("first") and print("second") on their own lines, instead of running together as firstsecond?

print("first")
print("second")
  • Because print's end defaults to a newline character, added after every call
  • Because the code is written on two separate lines
  • Because sep automatically adds a line break between separate print() calls

Why: Every print() call ends with end="\n" by default — a newline character — even though you never typed it. That's the actual mechanism behind something you already knew: each print() makes its own line.

print("Level: " + 5) — what happens when this runs?

print("Level: " + 5)
  • A TypeError — you can't + a string and a number together
  • It prints Level: 5
  • It prints Level:5 with no space

Why: A TypeError: can only concatenate str (not "int") to str. + glues text to text only — to fix it, wrap the number in str() first: "Level: " + str(5).

What you'll practice

The dragon wants one line: You have, then the number 12, then coins — all woven together with an f-string, not a comma. Fill in the blank: put coins (already set to 12) inside the {} where it belongs.

Start this lesson for real →

More from this topic

Building output is one lesson inside Python print() for Kids — see the full lesson order and what the whole topic covers.

View the full topic →