Python: Insert string into another string

0 Comments

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

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

[ Source ]

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