p设计一个Person类,属性有姓名、年龄、性别,创建方法personInfo,打印输出这个人的信息;创建Student类,继承Person类,属性有学院college,班级Group,重写父类Per

class Person:
    def __init__(self,name,age,sex):
        self.name=name
        self.age=age
        self.sex=sex
    def personInfo(self):
        print("姓名:",self.name,"年龄:",self.age,"性别:",self.sex)
class Student:
    def __init__(self,college,Group):
        self.college=college
        self.Group=Group
    def PersonInfo(self):
        print("学院:",self.college,"班级:",self.Group)
class sample(Person,Student):
    def __init__(self,name,age,sex,college,Group):
        Person.__init__(self,name,age,sex)
        Student.__init__(self,college,Group)
p=sample('小麦',20,'男','计算机科学',3)
p.personInfo()
p.PersonInfo()

p设计一个Person类,属性有姓名、年龄、性别,创建方法personInfo,打印输出这个人的信息;创建Student类,继承Person类,属性有学院college,班级Group,重写父类Per_第1张图片

你可能感兴趣的:(python,python)