How to take multiple inputs in a single line: Python?
Hello Coders, this tutorial deals with a program to take multiple inputs in a single line in Python.
Let us see a code to take one input.
s=input('Enter a character:')
Using the above code we can take input for any variable but if you want to take input of your preferred data type then use this syntax: datatype(input(‘<statement>’))
n=int(input('Enter a number:'))
If you want to take input for more than one variable then we generally go for below one.
a=input('Enter a character:') b=input('Enter a character:')
Take multiple input with a single line in Python
We can use it in a single statement also like below.
a,b=input(),input() print(a) print(b)
Here above code is single-line but we need to give input in multiple lines.
But if we want to code in a single line and also want to give input in a single line then go for split() method.
a,b=input(Enter two characters separated by space:').split()
So in these ways, we can take multiple inputs in a single line in Python. For any queries please comment below.
Also read: Python input( ) function