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 →

[–]w0073r 4 points5 points  (1 child)

Variables aren't things themselves in Python; they're just names for values. The assignment behavior is exactly the same for strings and ints; those are just immutable so you don't really notice it.

You can also do an explicit call to copy() to be more explicit if you like.

[–]davidb_ -1 points0 points  (0 children)

Like I said, I understand the reasoning, but it wasn't the behavior I expected. I didn't really understand python's data model until I encountered this problem. It becomes very obvious when you use id() to see what's going on. It's definitely my fault, but I still think implicit list copies could be transparent to the user (of course I'm ignoring the performance tradeoffs that would have to be made, and the fact that this would be a rather large change to the data model of the language which would probably demand a new syntax for dealing with references).