BaşlayınÜcretsiz Başlayın

Comparison and inheritance

In this exercise, let's test your understanding of what happens when an object from a parent class is compared to an object of a child class.

Consider the following two classes, which have been implemented and made available to you in 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

The Child class inherits from the Parent class, and both implement the __eq__() method that includes a diagnostic printout.

Bu egzersiz

Introduction to Object-Oriented Programming in Python

kursunun bir parçasıdır
Kursu Görüntüle

Uygulamalı interaktif egzersiz

İnteraktif egzersizlerimizden biriyle teoriyi pratiğe dökün

Egzersizi başlat