Life2Coding
How to Take Multiple Input from User in Python.

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

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.