Python Practice › Loop Programs › Program 48
Characters of a string into a list
Write a Python program that adds every character of an input string to an empty list.
Input
sqatools007
Output
Enter text: sqatools007 ['s', 'q', 'a', 't', 'o', 'o', 'l', 's', '0', '0', '7']
Approach
- Append each character in a loop.
Solution
text = input("Enter text: ")chars = []for ch in text: chars.append(ch)print(chars)Outputtyped input: sqatools007
Enter text: sqatools007 ['s', 'q', 'a', 't', 'o', 'o', 'l', 's', '0', '0', '7']
Tip
list(text) gives the same list in one call.
Learn the concept
New to this topic? Read the lesson, then come back.