Why does Python use 'magic methods'?
问题 I've been playing around with Python recently, and one thing I'm finding a bit odd is the extensive use of 'magic methods', e.g. to make its length available, an object implements a method, def __len__(self) , and then it is called when you write len(obj) . I was just wondering why objects don't simply define a len(self) method and have it called directly as a member of the object, e.g. obj.len() ? I'm sure there must be good reasons for Python doing it the way it does, but as a newbie I