Reputation: 3
I want to add to a list by user inputs. Here's my code:
list = []
list.append = int(input())
print(list)
When I run it I get this error:
AttributeError: 'list' object attribute 'append' is read-only
What am I missing?
Upvotes: 0
Views: 229
Reputation: 2260
Your problem is that you are trying to set the "append" attribute of the list to the new value. list.append
is the append attribute, which is read-only and can't be changed with list.append = newValue
(explication of your error), while list.append()
is the method which is actually what appends to your list.
list.append = int(input())
should be replaced with
list.append(int(input()))
Hope this helped.
Upvotes: 1