比較與繼承
在這個練習中,我們要考你是否理解:當父類別的物件與子類別的物件進行比較時,會發生什麼事。
請看以下兩個類別,已在 script.py 中實作並提供給你:
class Parent:
def __eq__(self, other):
print("Parent's __eq__() called")
return True
class Child(Parent):
def __eq__(self, other):
print("Child's __eq__() called")
return True
Child 類別繼承自 Parent 類別,兩者都實作了 __eq__() 方法,且包含用於診斷的列印訊息。
本練習屬於課程
