Technical Roadmap

Input in Python

We use the input() function to take input in Python.

Taking Input: The input() Function

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

When this function is called, the program pauses and waits for the user to type something and press Enter. Once Enter is pressed, the input is saved into a variable.

The Logicoria Tip

The input() function treats every input() as a String. Remember to use typecasting like int() or float() if you need to perform math on the input!

Python Program for taking username as input and print it.

PYTHON
# Taking input from the user
user_name = input("Enter your name: ")
print("Hello", user_name)

Output

Enter your name: Shivangi
Hello Riya

Characteristics of input():

  • Program Pause:
    Execution stops until the user provides input Resumes only after the "Enter" key is pressed
  • Default Data Type:
    Always returns data as a String (text) Even numbers are treated as text by default
  • Prompt Message:
    Tells the user exactly what kind of information is expected Prevents confusion by not leaving the terminal blank

Quick Revision

  • input() = Takes user data.
  • Prompts the user with a message.
  • Program waits for user to press Enter.
  • Always returns data in text (String) format.
  • Use int() or float() to convert numbers

Related Articles