Python print() and input(): Basic Console Output and Input

print() sends text and values to the console, and input() reads text typed by the user. Use print() when your program needs to show something, and use input() when it needs to ask for a response. This article explains how both functions work, how to combine them, and the mistakes that beginners make most often.

Difficulty: Beginner

Helpful to know first: basic Python syntax, variables, and how strings work.

How Python print() Shows Output and input() Reads Text

Python programs usually communicate through the console. print() writes data to standard output, which is what you see on screen. input() reads a line of text from standard input, which is usually your keyboard.

The important detail is that input() always returns a str, even if the user types numbers. If you want a number, you must convert that string yourself with int() or float().

Python
name = input("What is your name? ")
print("Hello,", name)
# If the user types Ada, the output is:
# What is your name? Ada
# Hello, Ada

Here, input() pauses the program until the user presses Enter. Then print() displays a greeting that includes the text the user entered.

Using print() to Display Text, Numbers, and Variables

The simplest use of print() is to display a message. You can also print variables, multiple values, and calculations.

Printing a message

This is the most basic case. Python shows the text exactly as written, except that it does not include the quotation marks.

Python
print("Python is running.")
# Output: Python is running.

Use this when you want to show instructions, results, or debugging information.

Printing several values

print() can accept more than one value. By default, it inserts a space between them.

Python
language = "Python"
version = 3.12
print("Learning", language, "version", version)
# Output: Learning Python version 3.12

This is useful when building messages from smaller parts. Python converts non-string values such as numbers into text automatically for printing.

Controlling spaces and line endings

You can change the separator between values with sep and the ending with end. These options matter when you want exact formatting.

Python
print("2026", "11", "03", sep="-")
print("Hello", end="!\n")
# Output:
# 2026-11-03
# Hello!

Use sep when you want a different separator between items, and use end when you want to avoid the default newline.

Using input() to Ask for User Input

input() shows a prompt, waits for the user to type, and returns what they typed as a string. The prompt is optional, but beginners usually should include one so the user knows what to enter.

Python
city = input("Which city do you live in? ")
print("You live in", city)
# If the user types Nairobi, the output is:
# Which city do you live in? Nairobi
# You live in Nairobi

The prompt string stays on the same line as the cursor because input() does not add a newline before waiting. That is why prompts usually end with a space.

Why input() gives you a string

Even when the user types digits, Python stores the result as text. This is why a program that adds two numbers must convert the input first.

Python
first_number = input("First number: ")
second_number = input("Second number: ")
print(first_number + second_number)
# If the user types 2 and 3, the output is 23, not 5.

That result happens because string concatenation joins text together. If you want arithmetic, convert the values first.

Combining print() and input() in Real Programs

Most small console programs follow the same pattern: show a prompt, read input, convert it if needed, then print a result. The examples below show that pattern in different forms.

Creating a simple greeting

This version asks for a name and uses it in a sentence.

Python
name = input("What is your name? ")
print("Nice to meet you,", name)

This works well for any text the user enters. No conversion is needed because the response is already text.

Adding numbers from the user

To add numbers, convert each input value to int before using +.

Python
first_number = int(input("First number: "))
second_number = int(input("Second number: "))
total = first_number + second_number
print("Total:", total)

Now + performs numeric addition instead of text joining. If the user types invalid text such as abc, int() raises an error, which is covered later in this article.

Printing formatted output with f-strings

F-strings are a common way to combine values into a message. They work especially well with input because they keep the code readable.

Python
name = input("Name: ")
age = int(input("Age: "))
print(f"{name} is {age} years old.")

This version is often easier to read than mixing many values in one print() call, especially when a sentence contains punctuation.

How print() and input() Behave in Detail

print() and input() are simple, but several details matter when you write real programs. These details explain many beginner mistakes.

print() converts values to text automatically

You can pass numbers, booleans, and other objects to print(). Python calls a string conversion on each value before showing it.

Python
count = 5
is_ready = True
print(count, is_ready)
# Output: 5 True

This is why print() is convenient for debugging: it accepts many kinds of values without extra work.

input() waits for Enter

The user does not need to type a special end marker. input() reads one line and finishes when the user presses Enter. It does not return until that happens.

If you want hidden password input or advanced terminal behavior, the standard library has other tools such as getpass, but plain input() is the right starting point for most beginner programs.

input() removes the trailing newline

When the user presses Enter, the terminal sends a line ending, but input() does not include it in the returned string. That is why the result usually looks clean when you print it back.

Python
value = input("Type something: ")
print("You typed", value)

The returned string contains the characters you typed, but not the Enter key itself.

Whitespace still matters in user input

input() keeps spaces the user typed. If the user enters " Ada ", those spaces stay in the string unless you remove them with strip().

Python
raw_name = input("Name: ")
clean_name = raw_name.strip()
print(f"Hello, {clean_name}!")

This is useful when you need to ignore accidental spaces from the keyboard.

Predict the Output

Text input and numeric addition are not the same

What does this print?

Python
a = "2"
b = "3"
print(a + b)
Show answer

It prints 23. Both values are strings, so + joins them instead of adding them.

Terminal
# Output: 23

Changing end changes the final line break

What does this print?

Python
print("A", end="")
print("B")
Show answer

It prints AB on one line. The first call does not add a newline, so the second call continues on the same line.

Terminal
# Output: AB

Common Mistakes with print() and input()

Using input() values as numbers without converting them

Many beginners read a number with input() and then try to do arithmetic immediately. The result is usually string concatenation or a type error in other operations.

Problem: The values from input() are strings, so this code joins text instead of adding numbers.

Python
first = input("First: ")
second = input("Second: ")
print(first + second)

Fix: Convert the text to a numeric type before adding it.

Python
first = int(input("First: "))
second = int(input("Second: "))
print(first + second)

The corrected version works because int() turns the text into integers before the addition happens.

Forgetting that input() always returns a string

This mistake often appears when a program compares user input to a number.

Problem: The comparison is between a string and an integer, so the condition does not behave as the writer expects.

Python
age = input("Age: ")
if age >= 18:
    print("Adult")

Fix: Convert the input before comparing it.

Python
age = int(input("Age: "))
if age >= 18:
    print("Adult")

The corrected version works because both sides of the comparison are numbers.

Typing input() without a prompt

Technically, input() can be called with no prompt. In beginner code, that usually makes the program confusing because the user does not know what to type.

Problem: The program waits for input without telling the user what is needed.

Python
value = input()
print("You typed", value)

Fix: Give the user a clear prompt.

Python
value = input("Type something: ")
print("You typed", value)

The corrected version works better because the prompt explains what the program expects.

Relying on print() spacing when exact formatting matters

By default, print() inserts spaces between arguments. That is helpful most of the time, but it can be wrong when you need exact output.

Problem: The default separator adds spaces that the programmer did not want.

Python
print("Name:", "Ada")
# Output: Name: Ada

Fix: Use one string, an f-string, or change sep.

Python
print("Name: Ada")
# Or:
print("Name:", "Ada", sep=" ")

The corrected version works because you choose the exact text that reaches the console.

Find the Bug

This program asks for two numbers and should print their sum. Find the bug before reading the solution.

Python
first = input("First number: ")
second = input("Second number: ")
total = first + second
print("Total:", total)
Show answer

The bug is that both inputs are strings. The + operator joins them, so typing 2 and 3 prints Total: 23 instead of Total: 5.

Fixed code:

Python
first = int(input("First number: "))
second = int(input("Second number: "))
total = first + second
print("Total:", total)

The fixed version works because the conversion happens before the addition.

When to Use print() and input(), and When to Use Something Else

print() and input() are the right tools for simple command-line programs, exercises, scripts, and beginner projects. They are not the only way to move data in and out of Python, though.

Use thisWhen it fitsWhat it does
print()You want to show text or values in the terminal.Writes to standard output.
input()You want to ask the user for a line of text.Reads from standard input and returns a string.
sys.stdout.write()You need low-level output control.Writes text without print()'s automatic spaces and newline.
getpass.getpass()You need secret input such as a password.Reads input without echoing it to the screen.

For most beginners, print() and input() are enough. Choose lower-level tools only when you need their special behavior.

How this differs from file input and output

Console input and output are interactive. File I/O is different because data is saved in a file rather than typed live by a user. If your program needs to remember data after it closes, file operations are the next topic to learn.

How this differs from GUI programs

Graphical programs do not usually use input() and print() for the main user experience. They use buttons, text boxes, and labels instead. The same idea still applies, though: a program receives input and produces output.

Interview questions

Why does input() return a string?

Because the keyboard sends text, not typed numbers or booleans. Python leaves interpretation to your code so you can decide whether the text should become an integer, float, or something else.

Why does print() add spaces between arguments?

It is a convenience feature. It makes mixed values readable without forcing you to build one large string every time. If you need different formatting, use sep, end, or an f-string.

When should I use int(input())?

Use it when you expect whole-number input and want to do arithmetic or integer comparisons. If the user might type decimals, use float() instead of int().

Try It Yourself

Write a program that:

  • asks for the user's name,
  • asks for their birth year,
  • prints a sentence that includes both values,
  • and calculates their age using 2026 as the current year.

Expected output example: if the user types Ada and 2000, the program should print something like Ada is 26 years old in 2026.

Hint: Use input() for both values, convert the birth year with int(), then subtract it from 2026.

Show solution
Python
name = input("Name: ")
birth_year = int(input("Birth year: "))
age = 2026 - birth_year
print(f"{name} is {age} years old in 2026.")

Summary

  • print() shows text and values in the console.
  • input() reads a line of text from the user and always returns a string.
  • Use int() or float() when user input should become a number.
  • print() adds spaces between arguments by default, and you can change that with sep and end.
  • Most beginner bugs come from forgetting that input() returns text, not numbers.
  • The next topic to learn is how Python stores values in variables and how those values flow through expressions.