我试图从字符串中删除一个单词,但前提是它是第二个单词。举个例子:
我试过脱衣换新。切片不起作用,因为Preds可能每次都不在同一个地方
# Complete the function to remove the word PREDS from the given string
# ONLY if it's not the first word and return the new string
def removePREDS(mystring):
return mystring.replace("PREDS", ' ')
# expected output: PREDS Rocks
print(removePREDS('PREDS Rocks'))
# expected output: Hello, John
print(removePREDS('Hello, PREDSFan'))
我可以删除pred和第一个,但不知道如何删除第二个
功能:
用法:
输出:
相关问题 更多 >
编程相关推荐