Python: Insert string into another string

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

def insert(original, new, pos):
'''Inserts new inside original at pos.'''
return original[:pos] + new + original[pos:]

[ Source ]

 
Copyright © Twig's Tech Tips
Theme by BloggerThemes & TopWPThemes Sponsored by iBlogtoBlog