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.
syntax:-
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()
syntax:-
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.
syntax:-
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.
Subscribe
Login
Please login to comment
0 Discussion