Curriculum / Python / Lesson 05

Input & Output in Python

Python's print() function outputs text to the console, and input() reads a line of text typed by the user.

5 of 11
beginner 📖 4 min read 🎯 1 question

Input & Output

Python's print() function outputs text to the console, and input() reads a line of text typed by the user. A key detail: input() always returns a string, even if the user types a number — you must convert it explicitly.

💡 Key insight input() always returns a string in Python — forgetting to convert numeric input with int() or float() is one of the most common beginner bugs.

Syntax

syntax
print(value1, value2, ...)
variable = input("prompt")

Example

int(age_text) converts the string returned by input() into a whole number so it can be used in math.

py
age_text = input("Enter your age: ")
age = int(age_text)
print("You are", age, "years old.")
outputEnter your age: 20 You are 20 years old.

Try it yourself

Copy this example into the Python compiler and run it — try changing a value and see what happens.

Quick Quiz

1. What type does Python's input() function always return?

Back to curriculum