⌨️
Reading input()
Get data from the user
Reward
+50 XP
Reading text
input() pauses and reads a line of text from the user. The result is always a string.
name = input("Your name: ")
print("Hello,", name)Reading numbers
Wrap input() with int() or float() to convert the text to a number.
age = int(input("Age: "))
print("Next year you'll be", age + 1)Multiple inputs
You can call input() multiple times to read several values.
first = input("First name: ")
last = input("Last name: ")
print(f"Hello, {first} {last}!")Try it yourself
Run the example below. Edit it and see what changes.
main.py
Output
Press Run to execute (Ctrl/Cmd+Enter)
Common mistakes
- ⚠Forgetting that input() returns a string. "5" + 1 will error.
- ⚠Using int() on text that isn't a number.
- ⚠Forgetting to store the result: input() alone discards the value.
