python 3クラスの演算子の再ロード
1549 ワード
#
#
class Try_str(str):
def __add__(self, other):
return int(self) + int(other)
def __sub__(self, other):
return int(self) - int(other)
'''
def __mul__(self, other):
def __truediv__(self, other): , /
def __floordiv__(self, other): , //
def __mod__(self, other): , %
def __divmod__(self, other): divmod() , ,
def __pow__(self, power, modulo=None): power() **
def __lshift__(self, other):
def __rshift__(self, other):
def __and__(self, other):
def __xor__(self, other):
def __or__(self, other):
'''
if __name__ == '__main__':
a = Try_str('123')
b = Try_str('12')
print(a+b)
print(a-b)