Python replace character in the list | Example code

Use regex to replace characters in the list in Python. Two of such functions within re is sub() and subn().

Example replace character in the list in Python

Simple example code removes multiple characters from a string. Removing “e”, “l’, and “p” char from given string.

You have to import the re module for this example.

import re

print(re.sub("e|l|p", "", "Hello Python Developers"))

Output:

Python replace character in the list

Do comment if you have any doubts and suggestions on this Python char topic.

Note: IDE: PyCharm 2021.1.3 (Community Edition)

Windows 10

Python 3.7

All Python Examples are in Python 3, so Maybe its different from python 2 or upgraded versions.


Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.