慕无忌2375754
2022-10-02 17:10
代码如下:
class Animal(object):
__localtion = 'Asia'
__count = 1
def __init__(self, name, age):
self.name = name
self.age = age
Animal.__count += 1
@classmethod
def get_count(cls):
return cls.__count
dog = Animal('wangwang', 1)
cat = Animal('mimi', 3)
pig = Animal('panpan', 1)
print(Aniaml.get_count())
报错如下:
Traceback (most recent call last): File "index.py", line 17, in count = Aniaml.get_count() NameError: name 'Aniaml' is not defined
检查仔细行不行,你看你的print里面的Animal是不是写错了
Python3 进阶教程(新版)
41910 学习 · 236 问题
相似问题