class Foo(str):
def __new__(cls, x, *args, **kwargs):
return super(Foo, cls).__new__(cls, x)
def __init__(self, x):
self.x = x
def __pos__(self):
return '+' + self.x
def __neg__(self):
return '-' + self.x
def __abs__(self):
return 'abs:' + self.x
def __invert__(self):
return 'invert:' + self.x
a = Foo('scolia')
print +a
print -a
print ~a
class Foo(str):
def __new__(cls, x, *args, **kwargs):
return super(Foo, cls).__new__(cls, x)
def __init__(self, x):
self.x = x
def __add__(self, other):
return self.x + '+' + other.x
def __sub__(self, other):
return self.x + '-' + other.x
def __mul__(self, other):
return self.x + '*' + other.x
def __floordiv__(self, other):
return self.x + '//' + other.x
def __div__(self, other):
return self.x + '/' + other.x
def __truediv__(self, other):
return self.x + 't/' + other.x
def __mod__(self, other):
return self.x + '%' + other.x
def __divmod__(self, other):
return self.x + 'divmod' + other.x
def __pow__(self, power, modulo=None):
return self.x + '**' + str(power)
def __lshift__(self, other):
return self.x + '<<' + other.x
def __rshift__(self, other):
return self.x + '>>' + other.x
def __and__(self, other):
return self.x + '&' + other.x
def __or__(self, other):
return self.x + '|' + other.x
def __xor__(self, other):
return self.x + '^' + other.x
a = Foo('scolia')
b = Foo('good')
print a + b
print a - b
print a * b
print a // b
print a / b
print a % b
print divmod(a, b)
print a ** b
print a << b
print a >> b
print a & b
print a | b
print a ^ b
from __future__ import division
.......
print a / b