remove punctuation and symbol python code example
Example 1: remove punctuation from string python
import re
s = "string. With. Punctuation?"
s = re.sub(r'[^\w\s]','',s)
s = "string. With. Punctuation?"
s.translate(str.maketrans('', '', string.punctuation))
Example 2: python remove punctuation from text file
import string
sentence = "Hey guys !, How are 'you' ?"
no_punc_txt = ""
for char in sentence:
if char not in string.punctuation:
no_punc_txt = no_punc_txt + char
print(no_punc_txt);
no_punc_txt = sentence.translate(sentence.maketrans('', '', string.punctuation))
print(no_punc_txt);