how can we take multiple value in one line | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

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

2nd Jul 2016, 1:01 PM
harsh sharma
harsh sharma - avatar
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.
2nd Jul 2016, 2:06 PM
Abhishek kumar
Abhishek kumar - avatar
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)
2nd Jul 2016, 2:36 PM
Gershon Fosu
Gershon Fosu - avatar