What is the problem with this loop?


#1

My code is below:

hobbies = []

Add your code below!

for i in range(3):
hobbies=raw_input("enter")
hobbies.append()

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


#2

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.append(item)

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


#3

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.


#4

yea, but both your list:

hobbies = []

and the variable in which you store the user input:

hobbies=raw_input("enter")

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

That is not working...


#5

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