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

 

公開された128元の記事 ウォン称賛90 ビュー4871

おすすめ

転載: blog.csdn.net/weixin_45405128/article/details/103928006