Menu
Try in Playground

Python print() and input(): Read User Input and Show Output

How Python's print() and input() functions work — plus separators, end characters, and how to convert user input to numbers.

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.

At its simplest, print() writes a line of text to the terminal:

main.py
Output
Click Run to see the output here.

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:

main.py
Output
Click Run to see the output here.

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:

main.py
Output
Click Run to see the output here.

Changing the separator

If a space between values isn't what you want, use sep:

main.py
Output
Click Run to see the output here.

Changing the line ending

By default print appends a newline. Use end to change that — for example, to keep output on the same line:

main.py
Output
Click Run to see the output here.

end="" is the trick for building up a line piece by piece.

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:

main.py
Output
Click Run to see the output here.

For formatted output — two decimal places, padded columns, commas in large numbers — use f-strings inside print:

main.py
Output
Click Run to see the output here.

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.

main.py
Output
Click Run to see the output here.

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:

main.py
Output
Click Run to see the output here.

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:

main.py
Output
Click Run to see the output here.

It strips nothing

Whatever the user types, including leading and trailing whitespace, comes back verbatim. If that matters for your logic, call .strip():

main.py
Output
Click Run to see the output here.

A Tiny Complete Program

Putting it all together — a few lines that ask the user for their info and print a small report:

main.py
Output
Click Run to see the output here.

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:

main.py
Output
Click Run to see the output here.

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.

Learn to code with Coddy

GET STARTED