Python Program to Remove Punctuations from a String

Write a Python program to remove punctuations from a string. We declared a string of possible punctuation characters and used for loop to iterate the given string. In this python example, the if statement checks each character against punctuations, and if it is not found, char will assign to a new string, which removes the punctuations.

# Python Program to Remove Punctuations in a String

punctuations = '''`[email protected]#$%^&*()-_=+{}[]\|;:'",.<>?'''

orgStr = "Hi!!, Welcome, Tutorial-Gateway?"

newStr = ""

for char in orgStr:
    if char not in punctuations:
        newStr = newStr + char

print("\nThe Original String Before Removing Punctuations")
print(orgStr)

print("\nThe Final String After Removing Punctuations")
print(newStr)
Python Program to Remove Punctuations from a String

This Python program allows the user to enter a string and removes the punctuations from it.

orgStr = input("Please Enter Any String = ")

punctuations = '''`[email protected]#$%^&*()-_=+{}[]\|;:'",.<>?'''

newStr = ""

for char in orgStr:
    if char not in punctuations:
        newStr = newStr + char

print("\nThe Original String Before Removing Punctuations")
print(orgStr)

print("\nThe Final String After Removing Punctuations")
print(newStr)
Please Enter Any String = [email protected]#&^%$# Python<>? Programs?

The Original String Before Removing Punctuations
[email protected]#&^%$# Python<>? Programs?

The Final String After Removing Punctuations
Learn Python Programs

Python program to remove punctuations from a string using a while loop.

orgStr = input("Please Enter Any String = ")

punctuations = '''`[email protected]#$%^&*()-_=+{}[]\|;:'",.<>?'''

newStr = ""

i = 0
while i < len(orgStr):
    if orgStr[i] not in punctuations:
        newStr = newStr + orgStr[i]
    i = i + 1

print("\nThe Original String Before Removing Punctuations")
print(orgStr)

print("\nThe Final String After Removing Punctuations")
print(newStr)
Please Enter Any String = [email protected] tutorial @@#&^ gateway {}\ followers

The Original String Before Removing Punctuations
[email protected] tutorial @@#&^ gateway {}\ followers

The Final String After Removing Punctuations
hi tutorial  gateway  followers