Categories
Python Answers

How to delete a character from a string using Python?

Spread the love

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.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *