insert chars into string

Felipe Almeida Lessa felipe.lessa at
Sat Mar 18 02:39:46 CET 2006

Em Sex, 2006-03-17 às 17:32 -0800, eight02645999 at escreveu:
> is there a string method to insert characters into a string?

As far as I know, no. Strings are immutable in Python. That said, the
following method may do what you want:

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

More information about the Python-list mailing list