Python Program to Remove Punctuations From a String Ad Sponsored

ⓘ Sponsored by

Punctuation refers to a set of marks used in written language to clarify meaning, indicate pauses or breaks in speech, and emphasize certain aspects of language such as intonation, emphasis, and tone. Punctuation marks include commas, periods, question marks, exclamation points, colons, semicolons, hyphens, dashes, parentheses, brackets, and quotation marks, among others.

Python Code :

The below Python program removes punctuations from a string:

import string

s = input("Enter string : ")
print("The string without any punctuations is : ", end=" ")  
for i in s:
    if i in string.punctuation:             
        i = ""
    print(i, end="")


  1. The program takes a string input from the user and stores it in the variable string s.

  2. The punctuation constant from the string module is used to get the list of all punctuation characters.

  3. The program uses a for loop to iterate over each punctuation character in the punctuations string. For each punctuation character, is replaced with a empty character in the original string.

  4. The resulting string without punctuations is displayed using the print() function

For Example:

Enter string : Hello-world !
The string without any punctuations is :  Helloworld Ad Sponsored

ⓘ Sponsored by