str.strip()
str.strip(characters)
Remove spaces at the beginning and at the end of the string.
- Input:
- characters : String, optional
- A set of characters to remove as leading/trailing characters. Default is white space " ".
- Returns:
- String with removed leading and trailing space or specified characters.
- Return Type:
- String
" panda ".strip()
"panda"
# The 'y' in 'baby' does not get stripped since its in the middle.
"...baby panda?! ".strip(".?! y")
"baby panda"
See Also
Problems or suggestions about this page? Fill out our feedback form.