TypeError: object of type 'str' has no len()

原创 向右看齐 2024-12-30 13:48 93阅读 0赞

The error message “TypeError: object of type ‘str’ has no len()” occurs when you try to call the len() function on a string, and the string does not have any length.

Here’s an example:

  1. my_str = "Hello"
  2. print(len(my_str)) # Raises TypeError

To fix this, you can either check if the string is empty or null before calling len(), or handle the error by using a conditional statement.

文章版权声明:注明蒲公英云原创文章,转载或复制请以超链接形式并注明出处。

发表评论

表情:
评论列表 (有 0 条评论,93人围观)

还没有评论,来说两句吧...

相关阅读