Describe the difference between objects and values using the terms “equivalent” and “identical”. Illustrate the difference using your own examples with Python lists and the “is” operator.
Object is an instance of a class while value is an object that assigns to a variable. “is” operator is used to test object identity while equivalent operator is used to test the identity of the object based on its values. “is” operator is used to know if two objects are equal or not while equivalent (==) is used to know if two operands are equal of not.
Example
l1 = [1,2,3]
l2 = [1,2,3]
if (l1 == l2):
print("True")
else:
print("False")
if (l1 is l2):
print("True")
else:
print("False")
Comments
Leave a comment