Question

You are using Python's built-in dict to store custom objects. class MyObject:     def __init__(self, value):         self.value = value     # Missing or incorrect __eq__ and __hash__ methods     # def __eq__(self, other):     #     return self.value == other.value     #     # def __hash__(self):     #     return hash(self.value) obj1 = MyObject(10) obj2 = MyObject(10) my_dict = {} my_dict[obj1] = "First" my_dict[obj2] = "Second" # Intended to overwrite "First" If the __eq__ and __hash__ methods are *not* implemented in MyObject, what will be the state of my_dict after the code executes?

A my_dict will contain obj1: "First" and obj2: "Second", treating them as distinct keys.
B my_dict will contain obj1: "Second", as obj2 will overwrite obj1.
C A TypeError will be raised because MyObject is not hashable.
D my_dict will be empty.
E my_dict will contain obj2: "First".
Practice Next

Hey! Ask a query