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
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+2by 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
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+2by 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
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+2by 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
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+2by itself doesn't work.