A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.geeksforgeeks.org/taking-multiple-inputs-from-user-in-python/ below:

Taking multiple inputs from user in Python

Taking multiple inputs from user in Python

Last Updated : 11 Jul, 2025

While taking a single input from a user is straightforward using the input() function, many real world scenarios require the user to provide multiple pieces of data at once. This article will explore various ways to take multiple inputs from the user in Python.

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).

Example:

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
How it Works:

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

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.

Example: 

Python
# Asking for multiple space-separated values
inputs = [i for i in input().split()]

print(inputs)

# taking multiple inputs at a time separated by comma
x = [int(x) for x in input().split(",")]
print(x) 

Output :

5 6 7 8
['5', '6', '7', '8']

Explanation:

Note: You can replace comma with any delimiter if you want to take inputs separated by space.

Using map() for Multiple Integer Inputs

If you need to collect multiple inputs in a single line and convert them into integers (or another data type), the map() function is useful. The map() function applies a specified function to each item in an iterable.

Example: Python
# Take space-separated inputs and convert them to integers
a = map(int, input().split())

# Convert the map object to a list and print it
b = list(a)
print(b)

Output:

5 6 7 8 9
[5, 6, 7, 8, 9]
Explanation: Taking Multiple Inputs in a Loop

If you want to collect multiple inputs from the user one at a time, you can use a loop. This is particularly useful when you need to collect an arbitrary number of inputs or perform validation on each input.

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:



RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4