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__魔法方
相關文章
相關標籤/搜索