What is the problem with this loop?


My code is below:

hobbies = []

Add your code below!

for i in range(3):

I run that, but receive AttributeError: 'unicode' object has no attribute 'append'.
What is the problem?


having the same name for both the list and the variable which stores the input is a bad idea. And you are using append wrong:


list_name is obviously the name of the list, and item is what you want to append to the list


What do you mean?
I want to store elements in hobbies which is empty so that I chose that name for that, but I am receiving errors like AttributeError: 'str' object has no attribute 'append'. Why? If I am mistaking, please explain a bit more.


yea, but both your list:

hobbies = []

and the variable in which you store the user input:


have the same name.... which means you list becomes a string (the user input)

That is not working...


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.