class Tool(object): count = 0 def __init__(self, name): self.name = name Tool.count += 1 # 定义一个数量的属性,我们就可以通过count知道创建的对象的数量 a = Tool('斧头') b = Tool('弓箭') c = Tool('剪刀') print(Tool.count) # 就像其他内置函数的属性一样,可以直接调用