0

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?

2
  • What exactly is your problem? What is happening when you run this code? What are you expecting to happen? Commented Mar 6, 2016 at 17:24
  • list.append = int(input()) AttributeError: 'list' object attribute 'append' is read-only. This is the error I'm confused about. I expecting to be able to add to the list by user input but I think either the code im using is wrong or I dont understand fully what I should write. Okay I think I understand what is going on. I cant add a list by user input cause .append is READ ONLY. So now I need to figure out how to add to the list another way? Commented Mar 6, 2016 at 17:28

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you for explaining this to me .

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.