初級 › AttributeError: object has no attribute 'length' の原因と直し方 › パターン2
AttributeError: object has no attribute 'length' の原因と直し方
他言語の.lengthや.size()の感覚でPythonのコレクションを扱おうとしたときに出るエラーです。
1 name = "hello" 2 print(___________) ^
Traceback (most recent call last):
File "main.py", line 2, in <module>
print(name.length)
^^^^^^^^^^^
AttributeError: 'str' object has no attribute 'length'
空欄を埋めて実行を通す
文字列の長さも同じくlen()です。他言語では文字列だけ.lengthのことがありますが、Pythonでは統一されています。
次の問題