and in Python, one solution is to take input() two times. Like this:-
//Taking two inputs
x, y= input(), input()
and other solution is to use split() function:-
//using split() function
x,y = input().split()
point to note here is that we have not explicitly specify split('') function here, that means it will take white space as its separator. while writing input where it encounter with space it takes next value as another input. For example:-
//split takes whitespace as default
x,y = input().split()
//input
Codin India
//output
Codin India
As we see here, we don't specify split() so it takes whitespace as separator.
NOTE:- Don't use Enter button after writing your first input. because when your
terminal encounters Enter button it will read next line instead of another
output. You will get this error
If you want to take input of multiple words. Like: Codin India as one input. You can specify split() with any character none other than symbol. That is because you will not going to take input a symbol.
Here I use "/" as split, that means whenever my input got encounter with / is will take next bit of code as input untill Enter.
You can also take 3 variable and more with Python in just one line:-
//taking 3 input in one line
x, y, z = input().split("/")
We can also use list comprehension:-
//List Comprehension
x,y = [int(i) for i in input().split()]
print(x,y)
If you want to learn python from scratch, you can refer this tutorial:- Python Tutorial
This article is contributed by Codin India. Please write comment if you find anything incorrect, or you want to
share more information about the discussed topic.
Bye! See you later☺
Good work
ReplyDeleteAwesome knowledge
ReplyDelete