可能重复:
子类 __init__ 覆盖超类的
class A():
z = 'z it is'
def __init__(self):
self.a = 'a it is'
class B(A):
def __init__(self):
self.b = 'b it is'
b = B()
print b.z # z it is
print b.a # AttributeError: B instance has no attribute 'a'
b
B
是从类继承的类的实例A
。这不意味着我可以访问父类的属性吗?