Add a method to the int class

placid Bulkan at gmail.com
Mon Jul 10 00:40:36 EDT 2006


barberomarcelo at gmail.com wrote:
> How can I add a method to the int class?

sub class it

>>> class MyInt(int):
>>>    def times(self,multiple):
>>>         return self * multiple
>>>
>>>  a = 2
>>>  print a
        2
>>>  a = MyInt(2)
>>>  print a
>>>  2
>>>  print a.times(2)
        4


--Cheers




More information about the Python-list mailing list