Why do some string methods have the varible inside the brackets and others outside


#1

During the lessons I have just used len() string method which I placed the Parrot variable within the brackets. The next task I used the .lower() string method and had to place parrot before e.g parrot.lower().
Why is that the case?


#2

length isn’t something that only strings have, but converting to lower case is specific to strings

in the end, it’s a way of organizing things. the code for figuring out the length of a string still exists with the string object, the len function is requesting the length from that

len could have been a method, the reason it’s not is that the length is something that a couple of protocols make use of, and there is therefore a preference for not using len or length as a name used for that protocol, but instead __length__, and then we use len to access that behaviour

a similar behaviour is to be iterable, which is how for-loops are able to iterate through lists, strings, dicts, sets and so on.


#3

because len() is a function call, while .lower() is a method, you will learn the difference later


#4

Thank you! That was helpful!