Input in Python

Input allows users to enter data into a program. Python uses the input() function to take input from the user.

💡 Data entered using input() is always treated as a string.

Basic Input Example

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

Input with Numbers

To take numeric input, we convert the input using int() or float().

age = int(input("Enter your age: "))
print("You are", age, "years old")
❌ Forgetting type conversion causes logical errors

Practice

  1. Ask the user for their city
  2. Add two numbers entered by the user