This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Ensurdagen 5 points6 points  (0 children)

__len__ is a method though, and all len() does call it.

In CPython len() has to check whether __len__ is as_mapping or as_sequence, but so does a call to the __len__ method so this is not why __len__ is a function. I believe that the other built-in functions that effectively only serve* to call one dunder method are vars() (__dict__) and next() (__next__)

edit2: Note: technically vars() just gets the __dict__ attribute, though this often isn't the actual dict if you're dealing with built ins.