파이썬기초52 : 클래스 상속03
작성자 정보
- 관리자 작성
- 작성일
컨텐츠 정보
- 1,691 조회
- 0 추천
- 목록
본문
class Person:
def __init__(self, name, phoneNumber):
self.Name = name
self.PhoneNumber = phoneNumber
def Printinfo(self):
print("Name:{0}, Phone Number: {1}".format(self.Name, self.PhoneNumber))
def PrintPersonData(self):
print("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
def PrintStudentData(self):
print("Student(Name: {0}, PhoneNumber: {1}, Subject: {2}, Student ID: {3}".format(self.Name, self.PhoneNumber, self.Subject, self.StudentID))
p = Person("Derick", "010-1234-5678")
s = Student("Marry", "010-8765-4321", "Computer Science", "990999")
print(p.Printinfo())
print(p.PrintPersonData())
s.Printinfo()
s.PrintPersonData()
s.PrintPersonData()
s.PrintStudentData()
print(p.__dict__)
print(s.__dict__)
print(issubclass(Student, Person))
print(issubclass(Person, Student))
print(issubclass(Person, Person))
print(issubclass(Student, Student))
print(issubclass(Student, object))
print(issubclass(Person, object))
print(Student.__bases__)
print(Person.__bases__)
s = Student("SUNGSOOPARK", "010-1234-5678", "Computer", "999999")
s.PrintStudentData()
관련자료
-
이전
-
다음