The str object has strip method. Any string is an str object so:
"any string".strip()
In [1]: s = "a string" In [2]: type(s) Out[2]: str In [3]: dir(s) Out[3]: # I've removed the __dunder__ functions to shorten the output ['capitalize', 'casefold', 'center', 'count', 'encode', 'endswith', 'expandtabs', 'find', 'format', 'format_map', 'index', 'isalnum', 'isalpha', 'isdecimal', 'isdigit', 'isidentifier', 'islower', 'isnumeric', 'isprintable', 'isspace', 'istitle', 'isupper', 'join', 'ljust', 'lower', 'lstrip', 'maketrans', 'partition', 'replace', 'rfind', 'rindex', 'rjust', 'rpartition', 'rsplit', 'rstrip', 'split', 'splitlines', 'startswith', 'strip', # here it is. 'swapcase', 'title', 'translate', 'upper', 'zfill'] In [4]: type("another string") Out[4]: str In [5]: "_strip it_".strip('_') # without an argument stip() will strip the whitespaces - ' \t\n\r\x0b\x0c' Out[5]: 'strip it'