remove leading and trailing characters whitespace by default from a string args userstring str the input string to be stripped characters str optional optional characters to be removed default is whitespace returns str the stripped string examples strip hello hello strip world world strip123hello123 123 hello strip remove leading and trailing characters whitespace by default from a string args user_string str the input string to be stripped characters str optional optional characters to be removed default is whitespace returns str the stripped string examples strip hello hello strip world world strip 123hello123 123 hello strip
def strip(user_string: str, characters: str = " \t\n\r") -> str:
    

    start = 0
    end = len(user_string)

    while start < end and user_string[start] in characters:
        start += 1

    while end > start and user_string[end - 1] in characters:
        end -= 1

    return user_string[start:end]