中級 › TypeError: takes N positional arguments but M were given の原因と直し方 › パターン3
TypeError: takes N positional arguments but M were given の原因と直し方
関数に定義されている数より多くの引数を渡したときに出るエラーです。
1 def square(x): 2 return x * x 3 4 print(square(______)) ^
Traceback (most recent call last):
File "main.py", line 4, in <module>
print(square(2, 3))
^^^^^^^^^^^^
TypeError: square() takes 1 positional argument but 2 were given
空欄を埋めて実行を通す
1つの値を2乗するだけの関数に、うっかり2つの値を渡すと発生します。
次の問題