The __eq__ method

__eq__(self, other)

A rich comparision method. See __lt__.

 

Comment:

i had to implement this today, this is what the class looks like class Foo(object): def __init__(self, val): self.Value = val def __eq__(self, other): return self.Value == other.Value foos = [Foo(1), Foo(2)] xfoo = Foo(2) print xfoo in foos # this calls the __eq__ function, will return True xfoo = Foo(4) print xfoo in foos # will return False when we implement __eq__ [equal], we should also implement __ne__ [not equal] for != or not in operators.

Posted by infogami

A Django site. this page was rendered by a django application in 0.01s 2008-10-13 13:14:02.963546. hosted by webfaction.