sentence = 'this is a sentence.'
replaced = ''
for c in sentence:
    if c == ' ':
        replaced += '*'
else:
    replaced += c
print(replaced)
Going character by character in a string and swapping whitespaces with python