Sometimes, we want to delete a character from a string using Python.
In this article, we’ll look at how to delete a character from a string using Python.
How to delete a character from a string using Python?
To delete a character from a string using Python, we can replace the character with an empty string.
For instance, we write
new_str = old_str.replace("M", "")
to call old_str.replace
to replace 'M'
with an empty string and return the string with the M removed.
And then we assign the returned string to new_str
.
Conclusion
To delete a character from a string using Python, we can replace the character with an empty string.