谢谢群主的分享
附带一个挺不错的举例的文章:
魔法方法(1)
魔法方法(2)
感谢楼主无私奉献!
小甲鱼万岁
有这个真的太棒了
已经收藏了
天!
class Nstr(str):
def __new__(cls, arg = ''):
if isinstance(arg, str) and arg:
a = arg.split(maxsplit = 1)
arg = len(a )
return str.__new__(cls, arg)
else:
print('Arguments\' type is wrong, must be string and length must at least one.')
def __lt__(self, other):
return int(self) < int(other)
def __le__(self, other):
return int(self) <= int(other)
def __eq__(self, other):
return int(self)== int(other)
def __ne__(self, other):
return int(self) != int(other)
def __gt__(self, other):
return int(self) > int(other)
def __ge__(self, other):
return int(self) >= int(other)
0. 不会
1. 当前项没有对应的方法时
2.基类.____
3.
慢慢玩转Python
好东西 收藏一下,学习了
魔法方法 一时还比较难以理解啊~~{:10_266:}
想知道这些怎么使用
我还在坚持学习,20190213
哇,太厉害了,这个
感觉都不会
小鱼鱼真优秀
本帖最后由 无兮丶 于 2019-4-9 17:42 编辑
玩什么我调用int.__isub__会显示int中没有__isub__呢
666666666
学习学习