As pointed out in answers above
myStringmy_string.strip() will remove all the leading and trailing whitespace characters such as \n\n, \r\r, \t\t, \f\f, space .
For more flexibility use the following
- Removes only leading whitespace chars:
myString.lstrip()my_string.lstrip() - Removes only trailing whitespace chars:
myString.rstrip()my_string.rstrip() - Removes specific whitespace chars:
myStringmy_string.strip('\n')ormyStringmy_string.lstrip('\n\r')ormyStringmy_string.rstrip('\n\t')and so on.