https://docs.python.org/3.7/tutorial/classes.html#method-objects
9.3.5. Class and Instance Variables
通常来看,实例变量是每个实例独有的,例如数据变量,而类变量,例如类属性和类方法,是类的所有实例共享的。
Generally speaking, instance variables are for data unique to each instance and class variables are for attributes and methods shared by all instances of the class:
class Dog: kind = 'canine' # class variable shared by all instances def __init__(self, name): self.name = name # instance variable unique to each instance >>> d = Dog('Fido') >>> e = Dog('Buddy') >>> d.kind # shared by all dogs 'canine' >>> e.kind # shared by all dogs 'canine' >>> d.name # unique to d 'Fido' >>> e.name # unique to e 'Buddy'