1#with re
2import re
3s = "string. With. Punctuation?"
4s = re.sub(r'[^\w\s]','',s)
5#without re
6s = "string. With. Punctuation?"
7s.translate(str.maketrans('', '', string.punctuation))
1import string
2#make translator object
3translator=str.maketrans('','',string.punctuation)
4string_name=string_name.translate(translator)
1# define punctuation
2punctuations = '''!()-[]{};:'"\,<>./?@#$%^&*_~'''
3
4my_str = "Hello!!!, he said ---and went."
5
6# To take input from the user
7# my_str = input("Enter a string: ")
8
9# remove punctuation from the string
10no_punct = ""
11for char in my_str:
12 if char not in punctuations:
13 no_punct = no_punct + char
14
15# display the unpunctuated string
16print(no_punct)
17
1import string
2sentence = "Hey guys !, How are 'you' ?"
3no_punc_txt = ""
4for char in sentence:
5 if char not in string.punctuation:
6 no_punc_txt = no_punc_txt + char
7print(no_punc_txt); # Hey guys How are you
8# or:
9no_punc_txt = sentence.translate(sentence.maketrans('', '', string.punctuation))
10print(no_punc_txt); # Hey guys How are you