The Two Functions That Make Your Program Interactive
Most early Python programs follow the same shape: ask the user for something with input(), do something with the answer, and report back with print(). These two built-ins are how your code talks to the world.
Let's take them one at a time.
print(): Writing Output
At its simplest, print() writes a line of text to the terminal:
That outputs the word hello followed by a newline. The newline is what separates one print call from the next on screen.
You can pass several values in one call, and Python will put a space between them:
Output:
Name: Ada Age: 36
The values don't need to be strings. print calls str() on each argument, so you can mix types freely:
Changing the separator
If a space between values isn't what you want, use sep:
Changing the line ending
By default print appends a newline. Use end to change that — for example, to keep output on the same line:
end="" is the trick for building up a line piece by piece.
print Goes to stdout
By default, print writes to stdout (standard output) — the normal place terminal output appears. You can redirect it to stderr, a file, or any other file-like object with the file argument:
For formatted output — two decimal places, padded columns, commas in large numbers — use f-strings inside print:
input(): Reading From the User
input(prompt) stops the program, shows the prompt to the user, and waits. Whatever the user types — until they hit enter — comes back as a string.
Three things about input that bite newcomers:
It always returns a string
Even if the user types 42, what you get back is the string "42". You can't do arithmetic on it directly:
That's why you'll often see int(input(...)) or float(input(...)) inline. If the user types something that isn't a valid number, int() raises ValueError — which we'll handle properly in the chapter on exceptions.
The prompt is optional
If you don't pass a prompt string, input() waits silently, which is almost always the wrong call — the user has no idea what you're asking for. Always pass a clear prompt:
It strips nothing
Whatever the user types, including leading and trailing whitespace, comes back verbatim. If that matters for your logic, call .strip():
A Tiny Complete Program
Putting it all together — a few lines that ask the user for their info and print a small report:
Twelve lines. It reads top-to-bottom like instructions, not like code. That's the style these docs are trying to encourage.
What About print-Based Debugging?
You'll sometimes hear that "real developers use a debugger, not print statements." That's overstated. Print is a perfectly good debugging tool, especially for small scripts and quick experiments. Sprinkle print calls liberally while you're figuring something out, and remove them when you're done.
Two small quality-of-life tricks:
The = inside an f-string prints both the name and value, which saves a lot of print("name =", name) boilerplate.
Moving On
print and input give you a full conversational loop: ask, read, respond. The next chapter starts mixing in conditions — the if statement and the operators that decide what your program does based on the values it sees.
Frequently Asked Questions
What does print() do in Python?
It writes values to the terminal. print("hello") outputs hello followed by a newline. You can pass multiple values separated by commas, and print() will put a space between them by default.
How does input() work in Python?
input(prompt) pauses the program, shows the prompt to the user, waits for them to type something and press enter, and returns what they typed as a string. Always a string — if you want a number, wrap the call in int(...) or float(...).
How do I print on the same line in Python?
Pass end="" to print. By default print adds a newline after the output; setting end to an empty string (or any other character) replaces that newline.