【发布时间】:2020-06-27 10:31:31
【问题描述】:
为什么实例变量b不起作用:
class Clothing:
a = 5
def __init__(self):
self.b = 0
shirt = Clothing
shirt.b
AttributeError: type object 'Clothing' 没有属性 'b'
为什么尝试访问 shirt.b 会引发 Attribute 错误?
【问题讨论】:
-
实例化类。
shirt = Clothing()
标签: python python-3.x oop instance