我的任務是撰寫一個 python 程式從串列(strings_list)中指定的字串(文本)中洗掉所有字符或字串。我得到了這樣,但這不起作用。任何人都可以告訴我我做錯了什么還是我使用了錯誤的功能?謝謝!!
def remove_strings(text, strings_list):
for strings_list in remove_strings:
strings_list.remove()
text_cleaned = remove_strings("yes, no, maybe..",
["yes", ","])
return text_cleaned
print(text_cleaned)
uj5u.com熱心網友回復:
def removechar(text, strings_list):
newstrings = []
for i in strings_list:
if text in i:
newtext = ""
newtext = i
newtext = newtext.replace(text, "")
newstrings.append(newtext)
else:
newstrings.append(i)
print(newstrings)
return(newstrings)
另外,.remove()不是函式,您必須.replace(text, "")改用
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/523697.html
標籤:Python功能
