We can use input() method in many forms. For converting the input entered by user into float we can use float() method as shown below:
x=float(input("Enter any number"))
print(type(x)) # float
We can also take multiple string input in a single line as follows:
Here we are taking two string inputs from the user in a single line using two input() function.
If we want to take space separated inputs using a single input() method then we can do like this.
split() function by default separates the input() if a space is comes between strings. Then first string before space character will go into the x and second into the y.
We can also separate inputs entered by user using another character also. For example:
x,y=input("Enter two strings :").split("/")
Note: We cannot directly convert string inputs in case when we are taking multiple inputs using a single input function means this will gives us error message:
x,y=int("Enter two values").split()
For such kind of inputs we have to do in this way:
x=float(input("Enter any number"))
print(type(x)) # float
We can also take multiple string input in a single line as follows:
Here we are taking two string inputs from the user in a single line using two input() function.
If we want to take space separated inputs using a single input() method then we can do like this.
split() function by default separates the input() if a space is comes between strings. Then first string before space character will go into the x and second into the y.
We can also separate inputs entered by user using another character also. For example:
x,y=input("Enter two strings :").split("/")
Note: We cannot directly convert string inputs in case when we are taking multiple inputs using a single input function means this will gives us error message:
x,y=int("Enter two values").split()
For such kind of inputs we have to do in this way:
Be First to Post Comment !
Post a Comment