operator overloading

Emile van Sebille emile at fenx.com
Mon Jun 5 16:14:53 EDT 2000


Here's a quick example of using __cmp__

>>> class Test:
 def __init__(self,a):
  self.a = a
 def __cmp__(self,other):
  return self.a < other.a


>>> a = Test(3)
>>> b = Test(4)
>>> print a<b
0
>>> print a>b
1


HTH,

Emile van Sebille
emile at fenx.com
-------------------


----- Original Message -----
From: <kazan at kazan.fenx.com>
Newsgroups: comp.lang.python
To: <python-list at python.org>
Sent: Monday, June 05, 2000 1:01 PM
Subject: operator overloading


> Hello
>
> How can I overload the less than operator?
> learning python did mention something about __cmp__ but
did
> not provide any examples.
>
>
> Thanks in advance
>
> Erling
> --
> http://www.python.org/mailman/listinfo/python-list
>





More information about the Python-list mailing list