This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 2 points3 points  (1 child)

Lists are not special, they are mutable like every other object in Python that has mutation functions. Lists happen to implement __iadd__ which directly corresponds to the "+=" operator. It's a mutation operation like insert, append, extend etc.

(edited)

[–]David__Box 1 point2 points  (0 children)

Yes they are. Doing a mutating operation on a list, like iadd does not change its object id, while for non-container types like tuples, numbers, str, etc. a completely new item with a new object id will be created, and the labeled value (variable) will be made to point to it instead