dict and __cmp__() question

Fredrik Lundh fredrik at pythonware.com
Wed Sep 7 03:56:39 EDT 2005


"Alex" <lidenalex at yahoo.se> wrote:

> But what are those with double underscore? For instance __cmp__(...)?
>
> I tried
>>>> D.cmp('a','b')

make that

    cmp('a', 'b')

methods that start and end with "__" are implementation hooks:

    http://docs.python.org/ref/specialnames.html

__cmp__ is used by cmp(a, b) and other operations that need to compare
things (unless "rich comparision" hooks are defined; see

    http://docs.python.org/ref/customization.html

)

other common hooks are __init__ (called after construction), __len__ (called
to determine the length of a sequence), __getitem__ (called to fetch an item
from a container), and a few others.  see the documentation for details.

</F> 






More information about the Python-list mailing list