top of page

5)Python Program to Remove Punctuation from a String

Punctuation:

The practice, action, or system of inserting points or other small marks into texts, in order to aid interpretation; division of text into sentences, clauses, etc., is called punctuation. -Wikipedia

Punctuation are very powerful. They can change the entire meaning of a sentence.

  • "Woman, without her man, is nothing" (the sentence boasting about men's importance.)

  • "Woman: without her, man is nothing" (the sentence boasting about women's importance.)

This program is written to remove punctuation from a statement.

See this example:

back.png

# define punctuation  

punctuation = '''''!()-[]{};:'"\,<>./?@#$%^&*_~'''  

# take input from the user  

my_str = input("Enter a string: ")  

# remove punctuation from the string  

no_punct = ""  

for char in my_str:  

   if char not in punctuation:  

       no_punct = no_punct + char  

# display the unpunctuated string  

print(no_punct)  

bottom of page