Discuss / Python / 打卡

打卡

Topic source

°Destiny

#1 Created at ... [Delete] [Delete and Lock User]
class Student(object):
    count = 0

    def __init__(self, name):
        self.name = name
        Student.count=Student.count+1  

# 根据本节想到类方法与实例方法
#两者区别在于定义类中方法的()内有无self参数
#类方法调用: 类名.方法名()  例如: Animal.run()
#实例方法调用: 实例名.方法名() 例如: dog.run()   dog=Animal()
#此外 类名().方法名()也是实例方法的调用,方法参数里必须含有self

  • 1

Reply