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.
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
secondprint'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
secondNow 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: 50There'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: 50f-strings never raise that TypeError, because the {} does the str() conversion for you, silently.
print(f"Total: {50}")Output
Total: 50One 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: 50Four 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")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)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.
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 →