print(): show words on the screen
print() is how your program talks. Whatever you put inside the ( ) shows up on the screen — the lines of your story, a score, anything at all.
The big idea
print() shows a value on the screen, on a new line each time you call it.
See it in code
print() is how your program talks. Whatever you put inside the ( ) shows up on the screen:
print("You wake up in a dark cave.")You wake up in a dark cave.
One print(), one line on the screen. Anything in the quotes appears exactly as you wrote it.
You can print words and a number together by separating them with a comma. Python even adds a space between them:
keys = 2
print("Keys in your pocket:", keys)Keys in your pocket: 2
The comma printed the words and the number 2 side by side, with a space in between — no gluing needed.
Now the opening of a text adventure. Each print() puts one more line on the screen, and the last one mixes words and a number with a comma:
print("You wake up in a dark cave.")
print("A torch flickers nearby.")
torches = 1
print("Torches you can grab:", torches)You wake up in a dark cave. A torch flickers nearby. Torches you can grab: 1
Three print() calls, three lines. Notice the comma put a space between Torches you can grab: and the number 1 for you.
print() is not just for stories. It shows a game's score, the result of some math, or a message telling you your code reached a certain line. When you cannot tell what your program is doing, printing is the first way to peek inside.
Try it yourself
Add a line that prints "Which way do you go?". Then make a box called gold = 5 and print "Gold:", gold so the player can see their treasure.
The common mistake
Forgetting the quotes. print(hello) makes Python hunt for a box named hello, and it crashes when there is not one. To print the word hello, wrap it in quotes: print("hello").
What it unlocks
Printing pairs with variables to show what your code remembers, and with input() to have a real back-and-forth with the player.