VOOZH about

URL: https://www.geeksforgeeks.org/python/taking-input-in-python/

⇱ Taking Input in Python - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Taking Input in Python

Last Updated : 29 May, 2026

Programs need to collect information from users, such as their name, age or a number. This is done using the input() function, which:

  • Pauses the program and waits for the user to type something.
  • Returns the entered value as a string (str).
  • Optionally displays a prompt message to guide the user.

Unlike some languages that rely on dialog boxes, Python keeps it simple by taking input directly from the console. This program asks the user for a value, stores it as a string and then prints it back.

Output

Enter your value: 123
123

input() Function Working

When you use input() in a program:

  • You can optionally provide a prompt message (e.g., "Enter your age:").
  • Whether you type letters, numbers, or symbols, Python always stores it as a string by default.
  • If you need another data type (like integer or float), you must convert it manually using typecasting.

Example: This program checks the data type of user input to confirm that both number and name are stored as strings.

Output

Enter number: 45
45
Enter name: John
John
Type of number: <class 'str'>
Type of name: <class 'str'>

Converting Input into Numbers

Often, you need numerical input (like age, marks, or salary). Since input() returns a string, you must convert it using int() or float().

Note: If the entered value cannot be converted (for example, int("abc")), Python raises a ValueError.

Example 1: Integer Input

This program converts user input into an integer.

Output

Enter a number: 25
25 is of type <class 'int'>

Example 2: Floating-Point Input

This program converts user input into a float (decimal number).

Output

Enter a decimal number: 19.75
19.75 is of type <class 'float'>

Taking Multiple Inputs

Sometimes, a program needs to accept more than one value at once. In Python, this can be done by entering values separated by spaces and then splitting them into separate variables.

Example: This program takes two numbers from the user in one input line, splits them and prints them separately.

Output

Enter two numbers separated by space: 10 20
First number: 10
Second number: 20

Related Posts:

Comment
Article Tags:
Article Tags: