python类对象的创建,代码如下所示:


class Student:
    company = "Google" #类属性
    count = 0 #类属性

    def __init__(self,name,score):
        self.name = name #实例属性
        self.score = score #实例属性
        Student.count += 1
    def say_score(self): #实例方法
        print("我的公司是",self.company)
        print("我的分数是",self.score)
s1 = Student("张三",90) #s1是实例对象,自动调用__init__()方法
s2 = Student("李四",80)
s1.say_score()
print("一共创建{0}个student对象".format(Student.count))


点赞(0) 打赏

Comment list 共有 0 条评论

暂无评论
立即
投稿
发表
评论
返回
顶部