0

Why str attribute error object has no attribute

I try to access method using dot " a = "Abdulrahman " print(a.len()) " instead of passing the variable as parameter of len() "print(len(a))" https://code.sololearn.com/cDgvlHi3AL6y/?ref=app

8th Dec 2020, 11:47 AM
Abdulrahman Muhammad
Abdulrahman Muhammad - avatar
2 odpowiedzi
+ 4
There is no .len() method on the `str` type. There is a .__len__() method which you can use, but you should stick to the usual approach of using the len(str_param) function to get the length
8th Dec 2020, 11:50 AM
XXX
XXX - avatar
+ 2
I think the reason is that there is actually no reason for len to be an attribute as it does not need any more parameters except the string or value itself
8th Dec 2020, 11:51 AM
noteve
noteve - avatar