Python Program to Remove Punctuation From a String

Python Program to Remove Punctuation From a String: This program removes all punctuations from a string. We will check each character of the string using for loop. If the character is punctuation, an empty string is assigned to it.

Python Program to Remove Punctuation From a String

Source Code

# define punctuation
punctuations = '''!()-[]{};:'"\,<>./[email protected]#$%^&*_~'''

my_str = "Hello!!!, he said ---and went."

# To take input from the user
# my_str = input("Enter a string: ")

# remove punctuation from the string
no_punct = ""
for char in my_str:
   if char not in punctuations:
       no_punct = no_punct + char

# display the unpunctuated string
print(no_punct)

Output of Program