Print Out, Input In
print() sends text to the screen while input() reads one line back from the person, always handing it over as a string. · 10 min
So far your programs have only talked to you. Now they can listen. A program has two channels to a person: print(...) sends text out to the screen, and input() reads one line back in — everything the person types until they press Enter. These two calls turn a fixed program into a conversation. There is one detail that trips nearly everyone the first time, and it is worth meeting head-on: whatever the person types, input() always hands it back as text, never as a number.
Guess before you learn
A program runs age = input() and you type 17 and press Enter. What is the type of the value stored in age?
It is a str — the text "17", not the number 17. input() cannot know whether you meant a count, a code, or a year, so it hands back the raw characters. If you guessed int, keep that mark: this is the single most common beginner surprise, and the next section shows the fix.
9–12
3–5
A program can show you things and ask you things. print("Hello") puts Hello on the screen. input() stops and waits until you type a line and press Enter, then gives your line to the program. Here is the catch worth remembering: input() always hands back text, never a number. If you type 12, the program receives the characters 12, which is a str — not the value 12. Adding 1 to it would fail. To get a number, the program wraps the text: int(input()) reads the line and turns it into a whole number you can compute with.
6–8
print(...) writes its arguments to the screen, then moves to a new line. input(prompt) shows the prompt, pauses the program, and returns everything you type up to Enter — as a str, always. This is the classic first-week surprise: age = input() followed by age + 1 raises an error, because age holds the string "17", not the number 17. The fix is a conversion: int(...) for whole numbers, float(...) for decimals. So age = int(input()) reads the line and converts it in one step. Output goes out as text; input comes back as text; numbers you have to ask for on purpose.
9–12
print and input are your program's two channels to a person: print writes a line to standard output; input reads a line from standard input and returns it with the trailing newline stripped. The return type is invariably str. This is deliberate — the program cannot know whether the characters you typed were meant as a number, a name, or a command, so it hands back the raw text and lets you decide. Converting is an explicit act: int("17") gives 17, but int("cat") raises a ValueError, which is Python honestly reporting that the text was not a number. Read the input, convert it, and check it — three separate responsibilities you will meet again and again.
K–2
Two words let a program talk with you. print shows words on the screen. input waits for you to type a line and press Enter. Print sends out. Input takes in.
Whatever you type, input hands back as text. Even if you type 7, the program gets the word 7, not the number. To do math with it, the program must turn the text into a number first.
Undergrad
input() is a thin wrapper over reading a line from the standard input stream; it blocks until a newline arrives and returns the line minus that newline, typed as str. There is no type inference at the I/O boundary — the edge between a program and the outside world is untyped text, and turning that text into structured values (parsing) is the program's job, not the runtime's. This is why robust input handling pairs conversion with error handling: int(s) is a partial function from strings to ints, undefined on "3.5" or the empty string, and a program that trusts its input without guarding the conversion is one malformed line away from a traceback. The habit of never trusting the shape of external input begins here.
Postgrad
The str-typed boundary of input() is an instance of a general principle: the edge of a system is untyped, and parsing is the act of lifting unstructured input into a typed domain where invariants can be enforced. int : str ⇀ int is partial, and a mature program makes the partiality explicit — validating, or catching ValueError — rather than letting an unhandled exception define its behaviour on bad data. Output is the dual: print serialises typed values back down to text via str(...), an often lossy projection. A surprising amount of practical software lives at exactly this membrane, converting between the disciplined interior of typed values and the formless text that people, files, and networks actually exchange.
input()
A call that pauses the program, reads one typed line, and returns it as text — a str, never a number.
The fix for the input surprise is one word wrapped around the other: int(input()). The input() reads the line as text, and int(...) turns that text into a whole number. Use float(...) instead when you expect a decimal. And if the person types something that is not a number at all, like cat, the conversion raises a ValueError — Python telling you, honestly, that the text was not a number. That is not the program breaking; that is the program refusing to guess.
Trace an input-and-add program — the steps fade as you master them
x = input() and you type 8. What value does x hold, and what type is it?x holds the text "8" (a str)
y = int(x). This converts the text to a number. What value does y hold now?y holds the number 8 (an int)
print(y + 1). Now the addition is between two numbers. What appears on the screen?9
Why is this true?
Why does input() return text even when you clearly typed a number?
Because the program cannot know what you meant the characters to be — a count, a name, a code. It hands back the exact text you typed and leaves the decision to convert to you, using int() or float() when a number is what you intend.
Note
Forgetting to convert input? The Atelier of Mind drills the read-then-convert habit until it is automatic.
Practice — new ink and old, interleaved
1.In your own words: what does an assignment like name = value do?
It binds the name to the value: Python stores the value and lets the name stand for it until you assign the name something else.
How close were you? Grade yourself honestly — it sets your review date.
2.Review from folio 2: what is the type of "7", written with quotes?
3.Which line reads a decimal number, like 3.5, from the person?
4.Review from folio 1: put these lines in the order they run.
- print("Ready?")
- answer = input()
- print("Go!")
5.You run n = int(input()) and type 6. Then print(n * 10) runs. What number appears?
6.Why does "3" + 5 cause an error?
7.What is the type of "7" — the 7 written inside quotes?