Why this error appears while adding characters to a list in Python?

Viewed 24

I am writing this simple program which prompts user a string and stores each character in a list. Although the program is very simple, this program is giving me hard time to identify why this error (IndexError: list assignment index out of range) is appearing.

str = input('Enter a string: ')
str_list = list()
x = 0
for i in str:
    str_list[x] = i
    x += 1
print(str_list)
0 Answers
Related