Inheritance from builtin list and override of methods.

Duncan Booth duncan.booth at invalid.invalid
Mon Nov 27 15:45:48 CET 2006

Michalis Giannakidis <mgiann at> wrote:

> On Monday 27 November 2006 11:50, Fredrik Lundh 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? 

I think it means that the statements are true in general, but there may be 
specific corner cases which break them. Usually you can assume that the 
rough description will be good enough.

> Is l[0]=1 completely different from l.append(1) or maybe insert?

Yes. It neither appends nor inserts.

> And is there a mechanism in Python that will allow me to override the 
> operators of a class, for all its occurrences, even the ones
> implemented on C built-in objects?


More information about the Python-list mailing list