Inheritance from builtin list and override of methods.

Fredrik Lundh fredrik at
Mon Nov 27 15:58:25 CET 2006

Michalis Giannakidis wrote:

>> "obj[index] = value" maps to "obj.__setitem__(index, value)".  reading
>> the documentation might help; start here:
> In this documentation page it also says:
> --snip---
> then x[i] is equivalent3.2 to x.__getitem__(i). 
> --snip--
> This, and other statements, are only roughly true for instances of new-style 
> classes. 
> --snip--
> So which statements are actually true for new style classes? 
> Is l[0]=1 completely different from l.append(1) or maybe insert?

l.append(1) is a method call.  L[0]=1 is syntactic sugar for a 
*different* method call.  why is this so hard to understand?


More information about the Python-list mailing list