Code Fix

中級TypeError: missing 1 required positional argument: 'self' の原因と直し方 › パターン3

TypeError: missing 1 required positional argument: 'self' の原因と直し方

クラスのメソッドをインスタンスを介さずに呼び出したときに出るエラーです。

 1  class Robot:
 2      def move(self):
 3          print("Moving")
 4  
 5  ___________.move()
         ^
Traceback (most recent call last): File "main.py", line 5, in <module> Robot.move() TypeError: Robot.move() missing 1 required positional argument: 'self'

空欄を埋めて実行を通す

広告
広告スロット(未設定)

TypeError: missing 1 required positional argument: 'self' の原因と直し方

selfには本来インスタンス自身が自動で渡されます。

このエラーの解説と類題をまとめて見る →

広告
広告スロット(未設定)