Re:Ruby is beautiful (but I'm moving to Python)
by masklinn on Sunday November 28, 2010 @02:53PM
(#1948099)
> len is a holdover from earlier python
No. len is basically a multimethod.
> (you can define a method __len__ if you want…)
You have to, it's part of the length protocol, `len()` will not work if you don't. Because `len(o)` calls `o.__len__()`). If you start calling underscore-methods directly (outside of a super() access), you're heading for trouble with your coworkers.
unlike 'self' in other languages as a keyword, 'self' is just a variable with the same scoping.
i.e self always refers to the most inner scope in other languages (a special variable), meanwhile self in python is wherever self was bound in the current scope.
and fwiw: len is a holdover from earlier python (you can define a method __len__ if you want...)