1

len() built-in function in python is called like this:

mylist = "Hello"
x = len(mylist)

On the other hand, the string built-in functions of str class are called using object with dot operator like this:

a = "Hello, World!"
print(a.lower())

Could someone please explain the reason of this difference in invocations of len() and other str methods like lower()?

  • 1
    Does this answer your question? [Why does Python code use len() function instead of a length method?](https://stackoverflow.com/questions/237128/why-does-python-code-use-len-function-instead-of-a-length-method) – Tom Burrows Jul 04 '20 at 18:31
  • @juanpa.arrivillaga My apologies. I thought <1.6.1 was not OO. I was wrong. – DYZ Jul 04 '20 at 18:33
  • Consider that you've correctly identified ``lower`` as a "function" *of the string type* specifically, but did not assume a specific type for ``len``. – MisterMiyagi Jul 04 '20 at 18:44

0 Answers0