python编程基础及应用(重庆大学):9-8 设计一个学生类

编写程序,设计一个学生类。包含姓名,学号及计数器三个属性,其中计数器属性用来统计实例化了多少个学生

#井号后的内容皆可不要
class Student:
    count=0     #类的计数属性
    def __init__(self,name,id):
        self.name=name
        self.id=id
        # self.Emotionalstate=""
        # self.qqnum=""
        # self.appearance=""
        # self.height=""
        # self.weight=""
        # self.age=""
        Student.count = Student.count + 1
    # def description(self):
    #     print("{0}是一个{1}的女孩,身高{2}cm,年龄{3}岁,体重{4}kg,目前感情状况{5},联系方式{6},冲冲冲!".
    #           format(self.name,self.appearance,self.height,self.age,self.weight,self.Emotionalstate,self.qqnum))

if __name__=="__main__":
    student1=Student("tutu","2020440001")
    #=============================================================#
    # student1.age="20"
    # student1.weight="45"
    # student1.Emotionalstate="single"
    # student1.appearance="pretty"
    # student1.height="155"
    # student1.qqnum="2117472285"
    # student1.description()
    #=============================================================#
    student2=Student("fanfan","2020440002")
    student3=Student("huanhuan","2020440003")
    print("已经实例化:",Student.count,"个学生")
")

运行结果:
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/qq_55977554/article/details/121318487