Is Len() A Function Or Method In Python?
In the context of object oriented programming, a function is different from a method. when i examine the help doc, this piece of code ?len outputs Signature: len(obj, /) Docstring
Solution 1:
There's one builtin lenfunction. You use it like len(obj). Each object can implements its own __len__ method to override what len() will return; len the function invokes __len__ the method.
If any object chooses to also implement a len method, it may do that, but that has nothing to do with the len function or __len__ convention.
builtin_function_or_method just means that the manual doesn't specifically distinguish between these two things and lumps them all into the same type.
Solution 2:
len() Is a function, while there is __len__() that is method.
read Here for more information.
Post a Comment for "Is Len() A Function Or Method In Python?"