- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to input multiple values from user in one line in Python?
In Python, to get values from users, use the input(). This works the same as scanf() in C language.
Input multiple values from a user in a single line using input()
To input multiple values in one line, use the input() method −
x, y, z = input(), input(), input()
Let’s say the user entered 5, 10, 15. Now, you can display them one by one −
print(x) print(y) print(z)
Output
5 10 15
From above output, you can see, we are able to give values to three variables in one line. To avoid using multiple input() methods(depends on how many values we are passing), we can use the list comprehension or map() function.
Input multiple values from a user in a single line using list comprehension
We have used the List Comprehension with the input() method to input multiple values in a single line −
a,b,c = [int(a) for a in input().split()]
Let’s say the user entered 1, 2, 13 Now, you can display them one by one −
print(x) print(y) print(z)
Output
1 2 3
Input multiple values from a user in a single line line using map()
The map() method can also be used in Python to input multiple values from a user in a single line −
a,b,c = map(int, input().split())
Let’s say the user entered 1, 2, 13. Now, you can display them one by one −
print(x) print(y) print(z)
Output
1 2 3
- Related Articles
- How to input multiple values from user in one line in C#?
- How to input multiple values from user in one line in Java?
- Take Matrix input from user in Python
- Taking multiple inputs from user in Python
- How to display multiple labels in one line with Python Tkinter?
- How to catch multiple exceptions in one line (except block) in Python?
- How to get Input from the User in Golang?
- How to create input Pop-Ups (Dialog) and get input from user in Java?
- Python Get a list as input from user
- How to populate an array one value at a time by taking input from user in Java?
- Iterate over lines from multiple input streams in Python
- Taking input from the user in Tkinter
- How to concatenate multiple C++ strings on one line?
- Swift Program to Get Input from the User
- Java Program to Get Input from the User
