User Input (input())

The input() function in Python is a built-in function used to accept input from the user through the keyboard.

It makes programs interactive and dynamic.

What is input() Function in Python?

The input() function is used to take data or information from the user while the program is running.

The value entered by the user is stored inside a variable and can be used later in the program.

Why User Input is Important

User input is important because it helps programs:

  • interact with users
  • accept dynamic values
  • perform real-time calculations
  • create personalized applications
  • improve user experience

Without user input, programs will always work with fixed values only.

Real-Life Analogy

User input is like a teacher asking a question and a student giving an answer.

  • Teacher asks → “What is your name?”
  • Student answers → “Ravi”

Similarly, a Python program asks and the user responds.

Syntax

variable_name = input("Message")


Usually we add a message:

input("Enter your name: ")

How input() Makes Programs Interactive

The input() function allows different users to enter different values.

For example:

  • one user can enter Rahul
  • another user can enter Akhil

The same program works for everyone dynamically.

Important:

By default, input() stores data as a string (text).

Example of User Input

name = input("Enter your name: ")
print("Hello", name)


Output

Enter your name: Ravi
Hello Ravi


Example - 1

age = input("Enter your age: ")
print("You are", age, "years old")


Output:

Enter your age: 12
You are 12 years old


Taking Number Input (Using Type Conversion)

Since input() stores text, we use int() or float() for numbers.

Example:

num = int(input("Enter a number: "))
print(num + 5)

Output:

Enter a number: 10
15

int() converts text into a number.

Practical Example

name = input("What is your name? ")
print("Welcome", name)

This is like asking a question and getting an answer.

Example

name = input("Enter your name: ")
age = int(input("Enter your age: "))

print("Hello", name)
print("Next year age:", age + 1)


Output

Enter your name: Ravi
Enter your age: 12

Hello Ravi
Next year age: 13


Common Mistake (Important)

Wrong:

age = input("Enter age: ")
print(age + 1)

 Error

Because input() stores a string.

Correct Way

age = int(input("Enter age: "))
print(age + 1)

 

Common Beginner Mistakes

Mistake Problem
Forgetting int() conversion Concatenation instead of addition
Mixing string and integer Raises error
Incorrect indentation Syntax problems
Missing quotation marks Invalid syntax

Why User Input is Important

User input in Python helps:

  • Make programs interactive
  • Accept information from users
  • Perform calculations
  • Build real applications

➤ Summary

  • input() is used to take user input
  • Input is stored as a string by default
  • Use int() or float() for numbers
  • Makes programs interactive and dynamic

Check your knowledge

Quickly verify what you've learned from this tutorial.

Question 1

Which function is used to take user input in Python?

input() is used to receive data from the user.

Question 2

By default, input() stores data as:

input() always stores user input as text (string).

Question 3

What is the output if user enters Ravi?
name = input("Enter name: ")
print("Hello", name)

The entered input is stored and printed with Hello.

Question 4

Why do we use int(input()) ?

int() converts user input from string to integer.

Question 5

What is the output if user enters 10?
num = int(input("Enter number: "))
print(num + 5)

int() converts input to a number, then Python adds 5.

Congratulations!

You've successfully mastered the knowledge check for "User Input (input())."

For more questions and practice, click the link below:

Practice More Questions
Previous Topic Type Conversion Next Topic Operators & Decision Making