Taking multiple inputs from user in Python

Last Updated : 26 Jun, 2026

Python allows users to enter multiple values in a single line or through repeated prompts. This is commonly used when collecting numbers, coordinates, names, or other sets of related data. Multiple inputs can be handled using split(), map(), list comprehensions, or loops depending on the required data type and input format.

Using input() and split()

One of the simplest ways to take multiple inputs from a user in Python is by using the input() function along with the split() method. The split() method splits a string into a list based on a specified separator (by default, it uses whitespace).

Python
# taking two inputs at a time
x, y, z = input("Values: ").split()
print(x)
print(y)
print(z)

Output: 

values: 5 6 7
5
6
7

Explanation:

  • input() takes the full input as a single string.
  • .split() divides the string into separate components based on whitespace by default.
  • The values are assigned to individual variables (x, y, z).

Let's take a look at other cases of taking multiple inputs from user in python:

Using map() for Multiple Integer Inputs

map() is useful when multiple inputs need to be converted to a specific data type, such as integers or floats. It applies a function to each input value and returns an iterable containing the converted values.

Python
# Take space-separated inputs and convert them to integers
numbers = list(
    map(
        int,
        input("Values: ").split()
    )
)
print(numbers)

Output

Values: 5 6 7 8 9

[5, 6, 7, 8, 9]

Explanation:

  • input() takes multiple values as a single string.
  • split() separates the string into individual values using whitespace.
  • map(int, ...) converts each value from a string to an integer.
  • list() converts the result into a list so it can be displayed and reused.

Note: Replace int with float, str, or another function if a different data type is required.

Using List Comprehension (Multiple Inputs in One Line)

If we want to ask the user for multiple values on a single line, we can use list comprehension combined with the input() function and split() to break the input into individual components. Also we can take inputs separated by custom delimiter which is comma in the below example.

Python
# Take space-separated inputs and convert them to integers
numbers = [
    int(x)
    for x in input("Values: ").split()
]

print(numbers)

Output :

Values: 5 6 7 8

[5, 6, 7, 8]

Explanation:

  • input() reads multiple values as a single string.
  • split() separates the input into individual values.
  • int(x) converts each value from a string to an integer.
  • The list comprehension iterates through each value and stores the converted results in a list.
  • print() displays the final list.

Note: List comprehensions are useful when you need to perform additional processing or transformations on each input value.

Taking Multiple Inputs in a Loop

A loop is useful when the number of inputs is unknown beforehand or when each input requires separate processing or validation.

Python
# Create an empty list to store the inputs
a = []

# Ask the user for how many items they want to input
b = int(input("How many items do you want to enter? "))

# Loop to collect multiple inputs
for i in range(b):
    val = input(f"Enter item {i + 1}: ")
    a.append(val)


for i in a:
    print(i)

Explanation:

  • The user first specifies how many inputs will be entered.
  • range() controls the number of iterations.
  • input() collects one value during each iteration.
  • append() stores each value in a list.

Taking Inputs Using a Custom Delimiter

By default, split() separates values using whitespace. It also accepts a separator argument, allowing users to enter values separated by commas, hyphens, or other delimiters.

Python
# Take comma-separated integer inputs
numbers = list(
    map(
        int,
        input("Values: ").split(",")
    )
)

print(numbers)

Output

Values: 5,6,7,8

[5, 6, 7, 8]

Explanation:

  • input() reads the entire input as a string.
  • split(",") separates the values using commas instead of spaces.
  • map(int, ...) converts each value to an integer.
  • list() stores the converted values in a list.
  • print() displays the final list.

Note: You can replace "," with any delimiter, such as "-", ":", or "|", depending on the input format.

Example: Using a Hyphen (-) as a Delimiter

Python
numbers = list(
    map(
        int,
        input("Values: ").split("-")
    )
)
print(numbers)

Output

Values: 10-20-30-40

[10, 20, 30, 40]

Methods Comparison

MethodBest Use Case
input().split()Multiple string inputs
map()Multiple numeric inputs
List comprehensionApplying custom transformations
split(delimiter)Comma-separated inputs
LoopUnknown number of inputs

list comprehension
input() function
split() method

Comment