>>> s = "aaa About DoctorTardi this Stats for Project Ares bbb"
>>> head, sep1, x = s.partition("About DoctorTardi")
>>> _, sep2, tail = x.partition("Stats for Project Ares")
>>> head + sep1 + sep2 + tail
'aaa About DoctorTardiStats for Project Ares bbb'
def remake_string(initialString, startPhrase, endPhrase):
startingIndex = initialString.rfind(startPhrase)e #finds the highest index of the phrase
endingIndex = initialString.find(endPhrase)# finds the lowest index of the phrase
newString = initialString[:startingIndex] + initialString[endingIndex:] '''
removes everything in the midding by starting getting everything up to the end of
the startPhrase and adding it to from the endPhrase on '''
return newString
将打印
x[:17]
是x的子字符串,从开始到第17个字母。x[25:]
是x的子字符串,从第25个字母到结尾。x[17:25]
是x的子字符串,从17个字母到25个字母 信。使用^{} 或^{} :
相关问题 更多 >
编程相关推荐