📱 Code Python on your phone with Python Coding - Learn PythonGet the free Android app →
  1. Home
  2. Learn
  3. Python input()

Guide · 3 min read

Python input(): how to take user input

input() is how a Python program asks the user a question. Here's everything beginners trip over — strings vs numbers, several values on a line, and invalid input — with examples you can run online.

Quick answerinput(prompt) shows the prompt, waits for the user to press Enter and returns what they typed as a string. Convert it with int() or float() for numbers, use input().split() for several values on one line, and wrap conversions in try/except ValueError to handle bad input.

The basics

Run ▸name = input("What's your name? ")
print("Nice to meet you,", name)

The program stops at input() until the user presses Enter. In the online compiler a box appears under the output — type your answer there. Many online compilers make you type all input in advance; this one pauses for real, exactly like a terminal.

input() always returns a string

This is the number-one beginner bug:

Run ▸a = input("First number: ")
b = input("Second number: ")
print(a + b)           # "2" + "3" -> "23", not 5!

Convert first:

Run ▸a = int(input("First number: "))
b = float(input("Second number: "))
print(a + b)

Several values on one line

Run ▸x, y = input("Enter two numbers: ").split()
print(int(x) * int(y))

scores = [int(s) for s in input("Scores: ").split()]
print("Average:", sum(scores) / len(scores))

split() breaks the line on spaces; use split(",") for comma-separated input. map(int, input().split()) is a common shortcut.

Handling bad input

Run ▸while True:
    raw = input("Enter your age: ")
    try:
        age = int(raw)
        break
    except ValueError:
        print(f"{raw!r} is not a whole number, try again.")
print("You are", age)

The loop keeps asking until int() succeeds. For yes/no questions, normalise first: input().strip().lower() == "y".

Reading until the user is done

Run ▸items = []
while True:
    item = input("Add item (blank to finish): ")
    if not item:
        break
    items.append(item)
print("Shopping list:", ", ".join(items))

EOFError

If a program asks for input when none is available — common on online judges or when you press Ctrl+D — Python raises EOFError. Catch it with except EOFError: if your program must cope with missing input.

Practise

The basics exercises are all input-and-output tasks with automatic checking.

Practise on your phone too

Python Coding - Learn Python for Android: a real Python 3 interpreter, code editor, 26 example programs and 12 marked exercises.

Get it on Google Play

Frequently asked questions

Why does input() return a string?

Python can't know what you expect the user to type, so it returns exactly the text typed. You decide how to convert it.

How do I take integer input in Python?

n = int(input()). For decimals use float(input()).

Which online Python compiler supports input()?

coding-python.com does, interactively — the program pauses at each input() and waits for you to type, like a real terminal.

How do I read input without a prompt?

Call input() with no argument.

Keep going

Published 2026-10-22 · Updated 2026-10-22 · by the Coding Python team · code tested on Python 3