私は Python の初心者で、クラスの継承を理解しようとしています。しかし、次のコードを試すと、このエラーが発生します。
AttributeError: 'child' object has no attribute '_name'
コードは次のとおりです。
class parent:
def __init__(self):
self._name = "Smith"
@property
def name(self):
return self._name
class child(parent):
def __init__(self, childname):
self._childname = childname
def getname(self):
return "child : {} .. parent : {}".format(self._childname, super().name)
def main():
Dad = parent()
Son = child("jack")
print(Son.getname())
if __name__ == "__main__":
main()
何故ですか ?Python のクラス継承を正しく理解していますか?