User Input in Python – Talk to Your Program!

⏱ 5 min read Beginner Last updated: Sep 2025

What if your Python program could ask you a question and actually use your answer? That's exactly what input() does. It lets your program pause, wait for the user to type something, and then use that data however you want. This is how real interactive programs work!

What is input()?

input() is a built-in Python function that reads a line of text typed by the user. Whatever they type gets returned as a string — every single time, no exceptions. That's the one big rule to remember.

Example 1: Basic Input

Python
name = input("What's your name? ")
print("Hey", name, "! Welcome to Kiddo.")

🔹 The text inside input() is the prompt — it shows up in the terminal asking the user what to type. The answer gets stored in name.

Example 2: Input is Always a String

Python
age = input("How old are you? ")
print(type(age))  # <class 'str'>

🔹 Even if the user types 18, Python stores it as the string "18", not the number 18. This is the most common beginner mistake!

Remember: input() always returns a string. If you need a number, you have to convert it manually using int() or float().

Example 3: Converting Input to a Number

Python
age = int(input("Enter your age: "))
print("In 10 years, you'll be", age + 10)

🔹 Wrapping input() with int() converts the string to an integer on the spot. Use float() if you expect decimal numbers.

Example 4: Using Input in an If Statement

Python
password = input("Enter the secret password: ")

if password == "kiddo123":
    print("Access granted!")
else:
    print("Wrong password. Try again.")

🔹 You can compare user input directly in conditions — no conversion needed when comparing strings.

Example 5: Taking Multiple Inputs

Python
first = input("First number: ")
second = input("Second number: ")

total = int(first) + int(second)
print("Sum:", total)

🔹 You can call input() as many times as you need. Each call waits for a separate line of input from the user.

Example 6: Input Inside a Loop

Python
for i in range(3):
    guess = input(f"Attempt {i + 1} — Guess the number: ")
    if guess == "7":
        print("Correct! You got it.")
        break
else:
    print("Out of attempts. The number was 7.")

🔹 Combining input() with loops lets you build retry logic — like a guessing game or login system with limited attempts.

Common Mistakes

Practice Time!

Build a simple calculator: ask the user for two numbers and an operator (+, -, *, /), then print the result. It's a great way to combine input, type conversion, and conditionals all at once!