New course! Every coder should learn Generative AI!
Try a free lesson0
how can we take multiple value in one line
like in c++ we use cin》a》b ; and when we run the code wo enter 2 3 .. so how can we take multiple values with space in python
2 Answers
+ 1
ele=list(map(int, input().split()))
this takes up all the value you enter in a line in the terminal and creates a list. you can assign a new name to the list as shown.
0
Using list comprehension
a = [int (x) for x in input().split ()]
Or if not many values are going to be input, like only 2 values.
a,b = int (input ().split ())
a,b = int (a), int (b)