+ 1
List. Help with list
Hi! I've been programming for a month and I have a question. When I do this: nums = list([(input())]) print (nums) the output Is not a list of numbers, but a string. Something like "3,4,5,6" if the input was 3,4,5,6. Question: Can I make a list of numbers [3,4,5] with the help of "input"??? I know that you can do this : list [] and every time you enter the desired data, I need it with " input" https://code.sololearn.com/cCKWp9uIreV8/?ref=app
4 Answers
+ 4
You can also do it this way:
nums = [int(x) for x in input().split(',')]
print(nums)
+ 2
this is simple.
x=input() #let x=1234
print(list(x)) #output=[1,2,3,4]
If input in ,
Then try this.
x=input() #let x=1,2,3,4
print(x.split(',')) output=[1,2,3,4]
But remember in this list numbers is a string not an integer for that you can use int() function for it.
+ 1
thank you very much