Remove all whitespace in a string

If you want to remove leading and ending spaces, use str.strip(): If you want to remove all space characters, use str.replace(): (NB this only removes the “normal” ASCII space character ‘ ‘ U+0020 but not any other whitespace) If you want to remove duplicated spaces, use str.split():

Remove all whitespace in a string

If you want to remove leading and ending spaces, use str.strip(): If you want to remove all space characters, use str.replace(): (NB this only removes the “normal” ASCII space character ‘ ‘ U+0020 but not any other whitespace) If you want to remove duplicated spaces, use str.split():