Python super()関数
例
別のクラスからすべてのメソッドとプロパティを継承するクラスを作成します。
class Parent:
def __init__(self, txt):
self.message = txt
def printmessage(self):
print(self.message)
class Child(Parent):
def __init__(self,
txt):
super().__init__(txt)
x = Child("Hello,
and welcome!")
x.printmessage()
定義と使用法
このsuper()
関数は、親クラスまたは兄弟クラスのメソッドとプロパティへのアクセスを提供するために使用されます。
このsuper()
関数は、親クラスを表すオブジェクトを返します。
構文
super()
パラメータ値
パラメータなし