Answers for "remove punctuation marks from srting object in python"

4

remove punctuation python

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);                 # Hey guys  How are you 
# or:
no_punc_txt = sentence.translate(sentence.maketrans('', '', string.punctuation))
print(no_punc_txt);                 # Hey guys  How are you
Posted by: Guest on May-21-2021

Code answers related to "remove punctuation marks from srting object in python"

Python Answers by Framework

Browse Popular Code Answers by Language