Single-character replacements are best left to str.translate():
try:
# Python 2
from string import maketrans
except ImportError:
# Python 3
maketrans = str.maketrans
def replace(original, char, replacement):
map = maketrans(char, replacement)
return original.translate(map)
str.translate() is by far the fastest option for per-character replacement mapping.
Demo:
>>> replace("banana", "a", "e")
'benene'
This supports mapping multiple characters, just make sure that both the char and replacement arguments are of equal length:
>>> replace("banana", "na", "so")
'bososo'
>>> replace("notabene", "na", "so")
'sotobese'
string.replace. Or did you mean "without using the string function or anything like string.replace"? In any case, show us the code you've written so far.