Write a Python program to delete all occurrences of a specified character in a given string


The program removes all occurrences of a specified character from a given string, and then prints the original and modified strings to the console. The program first initializes a variable ch with the value 't', and a string variable str with the value "Tutor Joes Computer Education".

The program then uses the replace() function to remove all occurrences of the character ch from the str string. The replace() function takes two arguments - the substring to be replaced, and the string to replace it with. In this case, since we want to remove the specified character, we replace it with an empty string ("").

The modified string is then stored in the variable res. Finally, the program prints the original string using the print() function and the str variable, and then prints the modified string res using the print() function. The first print statement serves as an indication of the original input string and the second print statement shows the string after removing all occurrences of the specified character.

Source Code

ch='t'
str="Tutor Joes Computer Education"
print("Original String :",str)
res = str.replace(ch, "")
print("Delete All Occurrences Specified Given String :",res)

Output

Original String : Tutor Joes Computer Education
Delete All Occurrences Specified Given String : Tuor Joes Compuer Educaion


Example Programs