Remove punctuations from a string

In this program, we will take a string as input and remove punctuations from a string.

Steps to solve the program
  1. Take a string as input.
  2. Create an empty string and a string containing all the punctuations.
  3. Use for loop to iterate over every character from the input string.
  4. If the character is not in the list containing punctuations then add that character to the empty string.
  5. Print the output.
				
					#Input string
string1 = "Sqatools : is best, for python"
string2 = ""
punc = '''!()-[]{};:'"\,<>./?@#$%^&*_~'''

for char in string1:
    if char not in punc:
        string2 += char
        
#Printing output
print(string2)
				
			

Output :

				
					Sqatools  is best for python
				
			

remove empty spaces from a list of strings.

find duplicate characters in a string

Leave a Comment