Look for a function like TRIM. If present, it can trim whitespace from the tail(default) or the head.
Python Trim String. strip(): returns a new string after removing any leading and trailing whitespaces including tabs (\t). rstrip(): returns a new string with trailing whitespace removed. ... lstrip(): returns a new string with leading whitespace removed, or removing whitespaces from the “left” side of the string. Python Trim String - rstrip(), lstrip(), strip() - JournalDev