■ issubclass 함수를 사용해 자식 클래스 여부를 구하는 방법을 보여준다.
▶ 예제 코드 (PY)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
class Person: "부모 클래스" def __init__(self, name, phoneNumber): self.Name = name self.PhoneNumber = phoneNumber def PrintData(self): print("Person(Name:{0}, Phone Number: {1})".format(self.Name, self.PhoneNumber)) class Student(Person): "자식 클래스" def __init__(self, name, phoneNumber, subject, studentID): self.Name = name self.PhoneNumber = phoneNumber self.Subject = subject self.StudentID = studentID print(issubclass(Person , object )) # True print(issubclass(Person , Student)) # False print(issubclass(Student, object )) # True print(issubclass(Student, Person )) # True |