Developer often wants a user to enter multiple values or inputs in one line. In C++/C user can take multiple inputs in one line using
scanf but in Python user can take multiple values or inputs in one line by two methods.
- Using List comprehension
Using split() method :
This function helps in getting a multiple inputs from user . It breaks the given input by the specified separator. If separator is not provided then any white space is a separator. Generally, user use a
split() method to split a Python string but one can used it in taking multiple input.
Using List comprehension :
List comprehension is an elegant way to define and create list in Python. We can create lists just like mathematical statements in one line only. It is also used in getting multiple inputs from a user.
Note : The above examples take input separated by spaces. In case we wish to take input separated by comma (, ), we can use following:
Please see https://ide.geeksforgeeks.org/BHf0Cxr4mx for a sample run.
- Python dictionary with keys having multiple inputs
- How to input multiple values from user in one line in Python?
- Python - Distance between collections of inputs
- Taking input in Python
- Taking input from console in Python
- Python Tweepy - Getting the name of a user
- Python Tweepy – Getting the URL of a user
- Python Tweepy - Getting the ID of a user
- Python - User object in Tweepy
- Python Tweepy – Getting the description of a user
- Take Matrix input from user in Python
- Python Tweepy - Getting the screen name of a user
- Add a User in Linux using Python Script
- Python User defined functions
- Python Tweepy - Getting the location of a user
- Python | Get a list as input from user
- Python Tweepy – Getting the number of friends of a user
- Python Tweepy – Getting the number of followers of a user
- User-defined Exceptions in Python with Examples
- Deleting a User in Linux using Python Script
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : rakeshsshankala