1.编写一个Person类,包含实例属性fullName、gender 和age.构造方法为_ init _(self.fullName, gender, age) ;类Student继承自Person,含有实例属性sno、school和speciaity.以及一个实例方法show().该方法打印实例的姓名、性别、年龄、学号、学院和专业。
1.编写一个Person类,包含实例属性fullName、gender 和age.构造方法为_ init _(self.fullName, gender, age) ;类Student继承自Person,含有实例属性sno、school和speciaity.以及一个实例方法show().该方法打印实例的姓名、性别、年龄、学号、学院和专业。
class Person:
def __init__(self, fullName, gender, age):
self.fullName = fullName
self.gender = gender
self.age = age
class Student(Person):
def __init__(self, fullName, gender, age, sno, school, speciaity):
super().__init__(fullName, gender, age)
self.sno = sno
self.school = school
self.speciaity = speciaity
def show(self):
print(self.fullName, self.gender, self.age, self.sno, self.school, self.speciaity)
s = Student(11,22,33,44,55,66)
s.show()
如果对你有帮助,可以点击我这个回答右上方的【采纳】按钮,给我个采纳吗,谢谢