I created some objects of a class in different ways and compared them. Try this using the below program. You can run it on https://repl.it
class Test:
pass
print("create an object of class Test and create a variable for the onject.")
obj1 = Test()
obj1.value = 5
print(obj1.value)
print("assign the object already created to a new varibale.")
obj2 = obj1
print(obj2.value)
print("create another object with same values but different variable name.")
obj3 = Test()
obj3.a = 5
print(obj3.a)
print("compare 1 and 3")
print("1 and 3 are same.") if obj1==obj3 else print("1 and 3 are NOT same.")
print("compare 1 and 2")
print("1 and 2 are same.") if obj1==obj2 else print("1 and 2 are NOT same.")
print("compare value of 1 and 3")
print("1 value and 3 a are same.") if obj1.value==obj3.a else print("1 a and 3 a are NOT same.")
print("compare value of 1 and 2")
print("1 value and 2 value are same.") if obj1.value==obj2.value else print("1 a and 2 a are NOT same.")
Comments
Post a Comment