How to take input by console in python, explain with example.
Explain the Python User Input
Ask by Anubhav Sharma
Updated 23 Oct 2025
1. What Is User Input?
Example use cases:
2. The
input()FunctionIn Python, you can take user input using the built-in
input()function.Syntax:
The message inside the parentheses (
"Your message here: ") is displayed on the screen.Whatever the user types is captured as a string (text).
Example:
Output:
3. All Input Is a String
Even if the user types a number, Python reads it as a string by default.
Example:
Output:
4. Converting Input to Numbers
If you want to perform calculations, you must convert the string to a number.
Convert to integer (
int)Convert to float (
float)5. Example — Simple Calculator
Output:
6. Using
input()with Multiple ValuesYou can take multiple inputs in one line and split them.
Example:
Output:
7. Prompt Customization and Formatting
You can make your prompt more readable using string format type:
8. Common Mistakes
num = input()thenprint(num + 5)int()eval(input())Summary
name = input("Enter your name: ")age = int(input("Enter age: "))price = float(input("Enter price: "))a, b = input().split()