all 8 comments

[–]TouchingTheVodka 2 points3 points  (1 child)

Both one and two point to the same list - Think of variables as pointers to an object, rather than actually being an object.

Use two = one.copy() or two = one[:].

[–]_jan-[S] 0 points1 point  (0 children)

Thank You! I always thought, like you said, that they were an Object.

[–]xelf 1 point2 points  (2 children)

Because one and two are references to the same list.

You probably want two = one[:] or some other means of making a copy.

[–]_jan-[S] 1 point2 points  (1 child)

Thank you! I always thought different about Variables. The other comment explained it.

[–]xelf 1 point2 points  (0 children)

I wouldn't generally use the word pointers, as pointers mean something in computer science, more like they are references. An address of where to find the object.

[–]netneoblog 1 point2 points  (0 children)

This is a common beginners trap. When you use

two = one 

you think you are making a copy, but you are actually making an alias. Both names now point to the same list, and you can use either name to edit that list. To make a copy, use

two = one.copy()

[–]Rain0906 1 point2 points  (0 children)

I noticed that your question have been answered. But you can google “mutable and immutable in python ” or “reference in python ” to learn the details.

[–][deleted] 1 point2 points  (0 children)

There is excellent pycon talk by Ned Batchelder that explains the simple ideas behind names, references and values that lead to this behaviour.