#/usr/bin/python3

x = [1,2,3,4]; #create a list with four entries
y = x	#set y to point at the same object
#Python does not allocate a variable to x and y as in other languages
# it sets x and y as pointers, aka references, to the object created.
# Interestingly, and seemingly incorrectly, Python sets y to point at
# the same object that x points at rather than as the statement says,
# point y at x

x[1] = 5; #re-assign ONE element
print("after change x is " + str(x)) #1 5 3 4 - as expected

print("after change y is " + str(y)) #1 5 3 4 #NOTE y changed TOO
#  this is because y is just a pointer/reference to the same object.
# This is wrong!  A change to x should not change y unless we
# understand that we are handling references which Python does 
# not mention.

x = ["one","two"]  #another assignment to x
print("the new x is " + str(x)) #one two as expected

print("and after the new assignment y is " + str(y)) #WEIRD?
#because Python set y to point at the same object, but now Python
# created a new object and so y continues to point at the OLD
# object and x points at the new one.
