初級 › AttributeError: object has no attribute 'length' の原因と直し方 › パターン1
AttributeError: object has no attribute 'length' の原因と直し方
他言語の.lengthや.size()の感覚でPythonのコレクションを扱おうとしたときに出るエラーです。
1 nums = [1, 2, 3] 2 print(___________) ^
Traceback (most recent call last):
File "main.py", line 2, in <module>
print(nums.length)
^^^^^^^^^^^
AttributeError: 'list' object has no attribute 'length'
空欄を埋めて実行を通す
リストの要素数はlen()という組み込み関数で取得します。他言語の.lengthや.size()のような書き方はPythonにはありません。
次の問題