By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,548 Members | 1,487 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,548 IT Pros & Developers. It's quick & easy.

Add a method to the int class

P: n/a
How can I add a method to the int class?

Jul 10 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a

ba************@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

Jul 10 '06 #2

P: n/a

<ba************@gmail.comwrote in message
news:11**********************@h48g2000cwc.googlegr oups.com...
How can I add a method to the int class?
You can't. The closest is to subclass int and add your method.

Jul 10 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.