""" reference assignment Now we will look at reference assignment where the object referenced is immutable. Later we will consider reference assignment when the object referenced is mutable. """ # First consider the assignment operator. var1 = 4 # sets var1 to reference the int object with a value of 4 # Now a different way the assignment operator can be used. var2 = var1 # sets var2 so it is a reference to the same object as var1 # not a new object with the same value, but the same object. # Of course the values are the same. print("var1:", var1) # resust: 4 print("var2:", var2) # resust: 4 # We can test that values are the same with the == operator print("var1 == var2:", var1 == var2) # result: True # each object has a unique id # we can see that var1 and var2 reference the same object # by looking at the id print( "var1:", id(var1) ) # result: 1517508928 print( "var2:", id(var2) ) # result: 1517508928 # we can test that the id values are the same. # This tests that the id value is the same object. print("var1 is var2:", var1 is var2) # result: True # now we can change one of them so they are different # the names refer to different objects with different values var2 = 5 print("var1:", var1) # resust: 4 print("var2:", var2) # resust: 5