Python 第十六天学习笔记

鸭子类型: class Nstr(str): def __sub__(self,other): return self.replace(other,'')      >>> a = Nstr("I love you aaaaaa") >>> b = Nstr("a") >>> a - b                    'I love you ' 当实现a-b操作时,触动__sub__魔法方
相关文章
相关标签/搜索