Removing punctuation in Python

41

remove punctuation from string python -

#with re
import re
s = "string. With. Punctuation?"
s = re.sub(r'[^\w\s]','',s)
#without re
s = "string. With. Punctuation?"
s.translate(str.maketrans('', '', string.punctuation))

clean punctuation from string python -

s.translate(str.maketrans('', '', string.punctuation))

Comments

Submit
0 Comments