+ 1

How to take input of string form user and store them in list in python

I want to take the user input and store the data in a list in python

20th Dec 2019, 5:14 AM
Sai Charan
Sai Charan - avatar
4 odpowiedzi
+ 1
user = input('Enter the string:') store = list(user) print(store)
20th Dec 2019, 6:04 AM
★«D.Connect_Zone»
★«D.Connect_Zone» - avatar
0
user_name = list(input("Enter the string: ")) print(user_name)
20th Dec 2019, 10:13 AM
Dilji
Dilji - avatar
0
It depends on how you enter the data. If the data in the input is separated by spaces, you can use input().split(). If it is separated by commas, you can use input().split(","), etc. For example: nums = input() #user input: "1,2,3,4,5" list_nums = nums.split(",") print(list_nums) #gives: ["1", "2", "3", "4", "5"] words = input() #user input: "these are some words" list_words = words.split() print(list_words) #gives: ["these", "are", "some", "words"]
20th Dec 2019, 11:09 AM
Njeri
Njeri - avatar
0
★«D.Connect_Zone» Dilji That doesn't quite work as it will split the string into a list of individual characters.
20th Dec 2019, 11:10 AM
Njeri
Njeri - avatar