class Nstr(str):
def __sub__(self, other):
return self.replace(other, '')
a = Nstr('I love FishC.com!iiiiiii')
b = Nstr('i')
print(a - b)
class Nstr(str):
def __lshift__(self, other):
return self[other:] + self[:other]
def __rshift__(self, other):
return self[:-other] + self[-other:]
a = Nstr('I love FishC.com!')
print(a << 3)
print(a >> 3)
class Nstr:
def __init__(self, arg=''):
if isinstance(arg, str):
self.total = 0
for each in arg:
self.total += ord(each)
else:
print('参数错误!')
def __add__(self, other):
return self.total + other.total
def __sub__(self, other):
return self.total - other.total
def __mul__(self, other):
return self.total * other.total
def __truediv__(self, other):
return self.total / other.total
def __floordiv__(self, other):
return self.total // other.total
a = Nstr('FishC')
b = Nstr('love')
print(a + b)
print(a - b)
print(a * b)
print(a / b)
print(a // b)
class Nstr(int):
def __new__(cls, arg=0):
if isinstance(arg, str):
total = 0
for each in arg:
total += ord(each)
arg = total
return int.__new__(cls, arg)
a = Nstr('FishC')
b = Nstr('love')
print(a + b)
print(a - b)
print(a * b)
print(a / b)
print(a // b)