Sometimes you may want someone to enter multiple input in one line,like scanf in C++/C you can’t take multiple values using only input() function. To do this you need to use split() method.
The split method’s syntax :
input().split(separator,maxsplit)
It breaks the given input (string) by the separator.If separator is not given,then it will consider a white-space as separator. Usually this method is used for splitting string. But also helpful for taking multiple input.
Example:
a,b,c=input("Enter 3 values here: ").split() print(a,b,c)
Output:
Enter 3 values here:1,2,3
1,2,3
Latest posts by Tahmid Samin (see all)
- How to Take Multiple Input from User in Python. - 22 April, 2022
- The Use of Setdefault Dictionary Methodin Python - 21 April, 2022