Describe the relationship between objects, references, and aliasing. Again, create your own examples with Python lists
Objects are instances of a class. For example a=[1,2,3], a is the object.
a=[1,2,3]
b=a
print(a is b)
In the above case b is a reference to the object a.
Since the same list above have two different names, a and b are said to be aliased.
Example
x = [1,2,3]
y = [1,2,3]
print(x == y)
print(x is y)
y = x
print(x == y)
print(x is y)
y[0] = 7
print(x)
Comments
Leave a comment