Home »
Python
Taking multiple inputs from user in Python
Last Updated : April 20, 2025
To understand the given examples for taking multiple user inputs, you should have knowledge of the following Python topics:
Taking multiple inputs at once
To take multiple inputs from the user in Python, you can simply use the combination of input() and split() method like input().split() and write the multiple values as input with separators/delimiters.
Let's understand the split() method.
Python split() method
The split() method is one of the library methods in Python, it accepts multiple inputs and brakes the given input based on the provided separator if we don't provide any separator any whitespace is considered as the separator.
Syntax
Below is the syntax to take multiple user inputs with separators:
input("Prompt Message").split([separator], [maxsplit])
Here, separator and maxsplit are the optional parameters, they can be used for the specified purposes.
Taking multiple inputs separated by whitespace
If the given input is separated by the whitespaces, you can use the .split() method without specifying the separator/delimiter.
Example
# input two integer numbers and print them
# Taking multiple inputs
a, b = input("Enter two integer numbers : ").split()
# Printing the values
print("a :", a, "b :", b)
# input name, age and percentages of the student
# and print them
name, age, perc = input("Enter student's details: ").split()
print("Name :", name)
print("Age :", age)
print("Percentage :", perc)
Output
Enter two integer numbers : 100 200
a : 100 b : 200
Enter student's details: Bharat 21 78
Name : Bharat
Age : 21
Percentage : 78
Taking multiple inputs separated by commas
If the given input is separated by the commas, you can use .split() method by specifying the comma (,) as a separator/delimiter in it.
Example
# input two integer numbers and print them
# Taking multiple inputs
a, b = input("Enter two integer numbers : ").split(",")
# Printing the values
print("a :", a, "b :", b)
# input name, age and percentages of the student
# and print them
name, age, perc = input("Enter student's details: ").split(",")
print("Name :", name)
print("Age :", age)
print("Percentage :", perc)
Output
Enter two integer numbers : 100,200
a : 100 b : 200
Enter student's details: Bharat,21,99
Name : Bharat
Age : 21
Percentage : 99
Python Taking Multiple Inputs Exercise
Select the correct option to complete each statement about taking multiple inputs from the user in Python.
- To take multiple inputs in a single line from the user, we use the ___ method in Python.
- When using the `input().split()` method, the default separator between inputs is ___.
- To convert each input value to an integer after using `input().split()`, we can use ___ in Python.
Advertisement
Advertisement