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.
- Python dictionary with keys having multiple inputs
- How to input multiple values from user in one line in Python?
- Taking input in Python
- Taking input from console in Python
- User-defined Exceptions in Python with Examples
- Python | User groups with Custom permissions in Django
- Fetch top 10 starred repositories of user on GitHub | Python
- Returning Multiple Values in Python
- Python | Initializing multiple lists
- Rename multiple files using Python
- Remove multiple elements from a list in Python
- Python | Iterate over multiple lists simultaneously
- Python | Interleave multiple lists of same length
- Print Single and Multiple variable in Python
- Python | Add similar value multiple times in list
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. 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.