根据教程要点:
The method replace() returns a copy of the string in which the occurrences of old have been replaced with new. https://www.tutorialspoint.com/python/string_replace.htm
因此可以使用:
>>> text = 'fhihihi'
>>> text.replace('hi', 'o')
'fooo'
有了这个想法,给定一个[1,2,3]
列表和一个'fhihihi'
字符串,根据它的位置,可以用某种方法来替换hi
为1、2或3吗?例如,该理论解将产生:
'f123'
任何解决方案都必须是无限扩展的。你知道吗
可以使用初始字符串创建format string:
使用^{} :
这将比使用
str.replace
的任何替代方法都要快得多一种含有
re.sub
的溶液:印刷品:
相关问题 更多 >
编程相关推荐