【发布时间】:2022-11-27 15:10:18
【问题描述】:
类变量
类车:
amount_cars = 0
def __init__(self, manufacturer, model, hp):
self.manufacturer = manufacturer
self.model = model
self.hp = hp
Car.amount_cars += 1
def print_car_amount(self):
print("Amount: {}".format(Car.amount_cars))
创建变量
myCar1 = Car("特斯拉", "Model X", 525)
打印变量
myCar1.print_info()
输出:
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
Input In [37], in <cell line: 1>()
----> 1 myCar1.print_info()
AttributeError: 'Car' object has no attribute 'print_info
需要帮助查找错误
【问题讨论】:
标签: python