• + 3 comments

    .strip() is a string method that by default removes any whitespace from either side of the whole string. e.g.

    " hello there ".strip()
    

    becomes "hello there"

    If you add an argument, it will instead remove whatever characters you put as the argument from either side of the string (not the middle). You will often see it used like this, to clean up words after using .split():

    import string
    word = "word!"
    word.strip(string.punctuation)