Answer to Question #282088 in Python for kika

Question #282088

Describe the relationship between objectsreferences, and aliasing. Again, create your own examples with Python lists


1
Expert's answer
2021-12-22T14:18:13-0500

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)

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS