TypeError: object of type 'str' has no len()
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:
my_str = "Hello"
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.
还没有评论,来说两句吧...