Python 的内置类型是否有多余的特殊方法?

Are there redundant special methods on Python's built-in types?

Fluent Python 他们说

You write len(my_object) and, if my_object is an instance of a user-defined class, then Python calls the __len__ instance method you implemented ...

But for built-in types like list, str, bytearray, and so on, the interpreter takes a shortcut: the CPython implementation of len() actually returns the value of the ob_size field in the PyVarObject C struct that represent the any variable-sized built-in object in memory.

但是 __len__ 仍然至少在其中一些上定义...

>>> 'string'.__len__()
6
>>> [1, 2, 3].__len__()
3

如果 len 不调用这些方法,它们有什么用?如果还有其他类似的例子,他们呢?

CPython 实现默认不调用 __len__() 的事实并不意味着没有任何 Python 库或用户程序可以调用.保持方法可用是关于 API 稳定性,即使 CPython 尽可能走捷径。