你可以 split 子字符串上的字符串,然后 join 它又回到了一起:
split
join
string = "Play soccer tomorrow from 2pm to 3pm @homies" times = ['tomorrow', 'from 2pm to 3pm'] for t in times: string = ''.join(string.split(t))
'Play soccer @homies' 因为在你的时代空间不会被捕捉和移除。
'Play soccer @homies'