In this blog, we will create simple program that will take any string as input from user and convert it into a list. Making each character of a string as an individual element in a list
Asking user to input any string
str = input('Enter a string: ')
Creating empty list
strtolist = []
Using for loop to access each character of a string and then adding it to end of the list using append method
for s in str:
strtolist.append(s)
Display elements in a list
print(strtolist)
Output
Enter a string: Python ['P', 'y', 't', 'h', 'o', 'n']
Complete Code
str = input('Enter a string: ') strtolist = [] for s in str: strtolist.append(s) print(strtolist)