To remove a specific character from a string in Python, you can use the `replace` method.
In this example,
str
with a value of "Hello World"
.replace
method to replace all occurrences of 'l' with an empty string in str
.replace
method returns a new string with the specified characters replaced.str
.str = "Hello World"
modified_str = str.replace('l', '')
print("Modified string:", modified_str)
Modified string: Heo Word
In this example,
str
with a value of "apple"
.replace
method to replace all occurrences of 'a' with an empty string in str
.replace
method returns a new string with the specified characters replaced.str
.str = "apple"
modified_str = str.replace('a', '')
print("Modified string:", modified_str)
Modified string: pple
In this tutorial, we learned How to Remove specific Character from a String in Python language with well detailed examples.