|
发表于 2018-3-12 16:55:58
|
显示全部楼层
本帖最后由 Chase_Kas 于 2018-3-26 23:06 编辑
学完类了!现在来答一下~~
- class Nint(int):
- def __truediv__(self, other):
- result = int.__truediv__(self, other)
- if int(result) == result:
- return int(int.__truediv__(self, other))
- else:
- return int.__truediv__(self, other)
- def __rtruediv__(self, other):
- result = int.__rtruediv__(self, other)
- if int(result) == result:
- return int(int.__truediv__(other, self))
- else:
- return int.__truediv__(other, self)
复制代码
看了其他人的发现右除可以直接调用上边的除!!哇,脑袋是个好东西,可惜我没有哦
- class Nint(int):
- def __truediv__(self, other):
- result = int.__truediv__(self, other)
- if int(result) == result:
- return int(int.__truediv__(self, other))
- else:
- return int.__truediv__(self, other)
- def __rtruediv__(self, other):
- return Nint.__truediv__(other, self)
复制代码 |
|