tring = "here are some words and a \n" print(tring.strip()) # won't replace all whitespace, only trailing and leading. print(tring.replace(" ", ""))