#Given two classes, Person and Student, where Person is the base class and Student is the derived class.
class Person:
def __init__(self, firstName, lastName, idNumber):
self.firstName = firstName
self.lastName = lastName
self.idNumber = idNumber
def printPerson(self):
print("Name:", self.lastName + ",", self.firstName)
print("ID:", self.idNumber)
class Student(Person):# Student 继承Person的属性
def __init__(self, firstName, lastName, idNumber, scores):
super().__init__(firstName, lastName, idNumber)#inheritance
self.scores = scores
Inheritance of Class in python
猜你喜欢
转载自blog.csdn.net/weixin_45405128/article/details/103928006
今日推荐
周排行