1. Uczyć się
  2. /
  3. Courses
  4. /
  5. Python 객체 지향 프로그래밍 입문

Connected

Exercise

비교와 상속

이 연습 문제에서는 부모 클래스의 객체와 자식 클래스의 객체를 비교할 때 어떤 일이 일어나는지 이해도를 점검해 보겠습니다.

다음 두 클래스가 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__() 메서드를 구현합니다.

Instrukcje 1 / 1

undefined XP
    1

Pytanie

  • 다음 코드를 실행하면 어떤 __eq__() 메서드가 호출될까요?*
p = Parent()
c = Child()

p == c 

Możliwe odpowiedzi