How to Remove Characters From a String in Python

One of the useful features of the Python programming language is the numerous methods it offers for text manipulation. You can use two methods to remove characters from a string of text; the method you choose depends on whether you want to remove from the string individual letters or specific letter sequences.

Video of the Day


Open the command prompt. In Windows, press the Windows-R keys and then type cmd in the Run field.


Type python to open the Python interpreter.


Define a string by typing:

s = "Hello World."


Type the following to strip the letters "o" and "l" from the string:

s = s.strip(['o','l'])

You must reassign the string to its own variable name. Strings in Python cannot be altered after they are defined. Instead, "strip" -- and other string methods -- produce a new string that you must assign to the old variable name.


Type the following to remove an entire word in the string:

s = s.replace("World", "")

Show Comments