I've defined a custom type which consists of, among other things, an unexported array.
What I'm wondering is, is there a way for me to override the implementation of the len()
function for my custom type without having to export the array?
Thanks.
New Python users are often surprised to learn that you call a global function named len() to get the number of items in a container.
The len() built-in function deals directly with built-in types: the CPython implementation of len() actually returns the value of the ob_size field in the PyVarObject C struct that represents any variable-sized built-in object in memory. This is much faster than calling a method -- no attribute lookup needs to happen.
The function len() is one of Python's built-in functions. It returns the length of an object. For example, it can return the number of items in a list. You can use the function with many different data types.
The LEN Function[1] is categorized under Excel TEXT functions. The function will return the length of a given text string. In financial analysis, the LEN function can be useful if we wish to get the length of a given text string as the number of characters.
No. You can however add a Len()
method to your type.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With