python字符串中插入字符串

来源:互联网 发布:轩辕剑3天之痕 mac 编辑:程序博客网 时间:2024/05/17 23:24

Sometimes you have to insert a string into the middle of another string, like "C" into "ABDE" so it becomes "ABCDE".

view sourceprint?
definsert(original, new, pos):
'''Inserts new inside original at pos.'''
returnoriginal[:pos] + new + original[pos:]


引自:http://twigstechtips.blogspot.com/2010/02/python-insert-string-into-another.html