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.
