
Mariheida C. answered 05/06/19
SAT/ACT Math, CS, Bilingual Spanish
To remove spaces or newlines from the beginning and end of a string, use the function strip(). Additionally, rstrip() removes them just from the end of the string and lstrip() removes them just from the beginning of the string.
For example:
> str = " Hello, world! \n"
> str.strip()
>>> "Hello, world!"
> str.rstrip()
>>> " Hello, world!"
> str.lstrip()
>>> "Hello, world! \n"