In this program, we will take a string as input and remove unwanted characters from the given string.
Steps to solve the program
- Take a string as input.
- Remove the unwanted characters using isalnum() and for loop.
- Print the output.
#Input string
string1="Prog^ra*m#ming"
test_str = ''.join(letter for letter in string1 if letter.isalnum())
#Printing output
print(test_str)
#Input string
string2="Py(th)#@&on Pro$*#gram"
test_str = "".join(letter for letter in string2 if letter.isalnum())
#Printing output
print(test_str)
Output :
Programming
Programming PythonProgram