🚀 Supercharge your YouTube channel's growth with AI.
Try YTGrowAI FreePython User Input from Keyboard – input() function

Python’s input() function lets your program pause and wait for the user to type something on their keyboard. When the user presses Enter, whatever they typed gets returned as a string value your code can work with. This makes input() essential for building interactive programs, command-line tools, and simple games where you need data from the person running your script.
Unlike many programming concepts, input() is straightforward to use. You call the function, optionally provide a prompt string, and Python gives you whatever the user entered. The main thing to remember is that the data always comes back as a string, so you need to convert it if you want numbers for math operations.
- input() pauses program execution until the user types and presses Enter
- All values returned are strings, even if the user types numbers
- Use int() or float() to convert string input to numeric types
- EOFError occurs when input() runs out of data to read, such as when piping empty input
Syntax of the input() Function
The input() function has a simple structure. The optional parameter is a prompt string that displays to the user before they type.
variable = input(prompt)
The prompt parameter is optional. If you omit it, Python displays nothing and waits silently. If you include a prompt, that text appears so users know what to do.
Reading User Input in Python
Here is a basic example that asks for the user’s name and then prints a greeting.
name = input("Enter your name: ")
print("Hello, " + name)
When you run this program, Python displays the prompt, waits for you to type, and then stores your response in the name variable. Running it might look like this in your terminal:
Enter your name: Alice
Hello, Alice
The Type of User Input
Everything input() returns is a string. This applies even when the user types something that looks like a number. You can confirm this with the type() function.
age = input("Enter your age: ")
print(type(age))
print(age)