Python Program to Remove Punctuation from a String

Created with Sketch.

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.

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.

See this example:

  1. # define punctuation
  2. punctuation = ”’!()-[]{};:'”\,<>./?@#$%^&*_~”’
  3. # take input from the user
  4. my_str = input(“Enter a string: “)
  5. # remove punctuation from the string
  6. no_punct = “”
  7. for char in my_str:
  8.    if char not in punctuation:
  9.        no_punct = no_punct + char
  10. # display the unpunctuated string
  11. print(no_punct)

Output:

Python Nativ Data Programs6

 

Leave a Reply

Your email address will not be published. Required fields are marked *