Python Program to Remove Punctuations From a String
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="")
The program takes a string input from the user and stores it in the variable string s.
The punctuation constant from the string module is used to get the list of all punctuation characters.
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.
The resulting string without punctuations is displayed using the print() function
Enter string : Hello-world ! The string without any punctuations is : Helloworld