How to take two inputs in one line in python?
Python gives us freedom to take the input from the user. The input we take from the user is read as string by default. After giving input we have to press “Enter”. Then only the input() function reads the value entered by the user.
We can take two input in one line also. There are some methods by which we can do that.
Here we’ll see this by using examples.
- split()- This function is used to take more than one input in a single line.
x, y=input("Enter the number:").split() print(x, y)
- map()- This is also used to take more than one input in a single line()
x, y=map(int, input("Enter the number:").split()) print(x, y)
- input()- We can write more than one input function in a single line to make our program small.
x, y= input("Enter the first number:"), input("enter the second number:") print(x, y)
In this way we can take more than one input in a single line.
Please login to comment
View all comments