Q:

Python Program to Remove Punctuation from a String

belongs to collection: Python String Programs

0

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.

See this example:

  • "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.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

# 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)  

 

Output:

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

How to reverse a string in Python?... >>
<< Python Program to Sort Words in Alphabetic Order...