|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 fc5igm 于 2021-6-15 22:44 编辑
- class Nstr(str):
- def __sub__(self,other):
- self.list=list(self)
- for other in self.list:
- self.list.remove(other)
- return ''.join(self.list)
复制代码- >>> a
- 'I love FishC.com!iiiiiiii'
- >>> list(a)
- ['I', ' ', 'l', 'o', 'v', 'e', ' ', 'F', 'i', 's', 'h', 'C', '.', 'c', 'o', 'm', '!', 'i', 'i', 'i', 'i', 'i', 'i', 'i', 'i']
- >>> a.list
- ['e', ' ', 'F', 's', 'C', 'c', 'o', 'm', 'i', 'i', 'i', 'i']
复制代码
同样是调用list类,为什么list(a)正常,self.list就是这么诡异的东西?
你把 other 拿去接收循环了,把 for 循环改成这样就正常了:
- for i in other:
- self.alist.remove(i)
复制代码
|
|