0

in Python3.2 I'm trying to do a list:

>> ls = 1, 2, 3
>> ls
(1, 2, 3)
>> ls.append(4)

And with this last command, I get the following error:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'tuple' object has no attribute 'append'

Why is this? How can I solve it? Thanks for your time

1 Answer 1

6

The syntax for a list is [1, 2, 3].

(1, 2, 3) is a tuple.

Lists are mutable, but tuples are immutable. That is, tuples can't be modified after they have been created (which is why you can't append to them).

This answer has great insight as to when you'd use one over the other.

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

1 Comment

Thank you very much! That was a great help.

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.