How do I strip all leading and trailing punctuation in Python? [duplicate]
You do exactly what you mention in your question, you just str.strip it.
from string import punctuations = '.$ABC-799-99,#'print(s.strip(punctuation))
Output:
ABC-799-99
str.strip can take multiple characters to remove.
If you just wanted to remove leading punctuation you could str.lstrip:
s.lstrip(punctuation)
Or rstrip any trailing punctuation:
s.rstrip(punctuation)