萌新想问一下,为啥老是报错提示无法解释为整数
class Nstr(str):def __sub__(self,other):
self = list(self)
other = list(other)
for i in other:
self.pop(i)
print(str(self))
a = Nstr('i love you and she')
b = Nstr('and she')
a - b for i in other: # other列表:['a', 'n', 'd', ' ', 's', 'h', 'e'],i就是一个个字符,
self.pop(i)# 列表pop得写元素的index,但i是字符串,所以报错。 本帖最后由 jackz007 于 2021-11-23 17:59 编辑
class Nstr(str):
def __sub__(self,other):
self = list(self . split())
other = list(other . split())
for i in other:
self . remove(i)
print('' . join(s + ' ' for s in self))
a = Nstr('i love you and she')
b = Nstr('and she')
a - b suchocolate 发表于 2021-11-23 17:37
谢谢谢谢,我脑壳瓦特了{:5_105:} jackz007 发表于 2021-11-23 17:53
谢谢谢谢{:5_101:} {:10_256:}
页:
[1]