;

Python Program to Remove Punctuations or Special Character From a String


Tutorialsrack 23/04/2020 Python

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

After Removing Punctuations or Special Characters, the String is: 

Hello he said and went


Related Posts



Comments

Recent Posts
Tags