Python str.strip: Removing any characters, not just whitespace

Python str.strip: Removing any characters, not just whitespace

By default, str.strip in Python removes leading/trailing whitespace:

s = '   a b c   '
s.strip()  # returns 'a b c'

It takes an optional argument, naming leading/trailing characters to remove. Great for cleaning strings:

s = '"Hello!"'
s.strip(string.punctuation)  # 'Hello'