In this Python Program, we will learn how to remove punctuations or special characters from a string. In this program, we will remove the special characters such as #,::./][$%^&*, etc.
Here is the code of the program to remove punctuations or special characters from a string.
# Python Program to Remove Punctuations or Special Characters From a String
# define punctuation
punctuations = '''!()-[]{};:'"\,<>./?@#$%^&*_~'''
my_str = "#Hello!!!, he said @---and? went."
# To take input from the user
# Uncomment below Line of code
# my_str = input("Enter a string: ")
# remove punctuation or Special Characters from the string
no_punct = ""
for char in my_str:
if char not in punctuations:
no_punct = no_punct + char
# display the string After Removing Punctuations or Special Characters
print("After Removing Punctuations or Special Characters, the String is: ")
print(no_punct)
After Removing Punctuations or Special Characters, the String is:
Hello he said and went
Comments