0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Pythonでsuper()の呼び出し時、selfは暗黙的に渡される

Posted at

久しぶりにpython書いてるとよく間違えちゃうんのでメモ。

python3 でsuper()を使う場合、第一引数としてselfは暗黙的に渡される。

なので下記2例はどちらも同じ意味

super()で親クラスのメソッド呼び出す場合
class A(Base):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs) # self引数は不要
super()を使わない場合
class B(Base):
    def __init__(self, *args, **kwargs):
        Base.__init__(self, *args, **kwargs)
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?