def hide(string, replace_with):
for char in string:
if char not in " !?.:;": # chars you don't want to replace
string = string.replace(char, replace_with) # replace char by char
return string
print hide("Hello how are you", "x")
'xxxxx xxx xxx xxx'
Also check out the string and re modules.