how to remove punctuation and \n from a string 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: remove punctuations using python
punctuations = '''!()-[]{};:'"\,<>./?@#$%^&*_~'''
my_str = "Hello!!!, he said ---and went."
no_punct = ""
for char in my_str:
if char not in punctuations:
no_punct = no_punct + char
print(no_punct)