Inheritance of Class in python

#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

 

Published 128 original articles · won praise 90 · views 4871

Guess you like

Origin blog.csdn.net/weixin_45405128/article/details/103928006