Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.
Code Golf

Return to Answer

Commonmark migration
Source Link

Python 2

#Python 2 yayyay operator overloading :P

class int:
 number = 2
 def __init__(self, number): 
 self.number = number
 def __add__(self, other):
 return self.number + other.number + 1
 
two = int(2) # works without above def!
print two + two

try on ideone!

pretty simple to understand, just overwrites the int class with a new one that adds one to each addition thing. Seriously I'm surprised print 2+2 by itself doesn't work.

#Python 2 yay operator overloading :P

class int:
 number = 2
 def __init__(self, number): 
 self.number = number
 def __add__(self, other):
 return self.number + other.number + 1
 
two = int(2) # works without above def!
print two + two

try on ideone!

pretty simple to understand, just overwrites the int class with a new one that adds one to each addition thing. Seriously I'm surprised print 2+2 by itself doesn't work.

Python 2

yay operator overloading :P

class int:
 number = 2
 def __init__(self, number): 
 self.number = number
 def __add__(self, other):
 return self.number + other.number + 1
 
two = int(2) # works without above def!
print two + two

try on ideone!

pretty simple to understand, just overwrites the int class with a new one that adds one to each addition thing. Seriously I'm surprised print 2+2 by itself doesn't work.

Source Link

#Python 2 yay operator overloading :P

class int:
 number = 2
 def __init__(self, number): 
 self.number = number
 def __add__(self, other):
 return self.number + other.number + 1
 
two = int(2) # works without above def!
print two + two

try on ideone!

pretty simple to understand, just overwrites the int class with a new one that adds one to each addition thing. Seriously I'm surprised print 2+2 by itself doesn't work.

AltStyle によって変換されたページ (->オリジナル) /