import sys
len
Above, the built-in string function is an object. This object is an callble object. To check if an object is callable, we can use function callable.
callable(len)
What about "callable", must be an callable object?
callable
callable(callable)
callable(True)
Note the object True is not an callable object. We cannot do True().
True()
The function objects have dunder format of calling them. See below:
"string".__len__
"string".__len__()
You can try yourself with all the datatypes and values to see if they are objects. The type objects return empty object instance of that type. Check the below:
str()
int()
dict()
Since numbers are also object, we can do the addition this way too:
5.67.__add__
callable(5.67.__add__)
5.67.__add__()
5.67.__add__(2)
We can get the size of the objects in bytes using sys.getsizeof() function.
sys.getsizeof('a')
sys.getsizeof('abcd')
Above, since the values are stored in the objects, the size of 'abcd' is just three bytes more than size of 'a' which is 50 bytes. More examples:
sys.getsizeof(1)
sys.getsizeof(2**30-1)
sys.getsizeof(2**30)
Reference: Stuart Williams - Python Epiphanies - PyCon 2018 https://www.youtube.com/watch?v=-kqZtZj4Ky0&t=498s