Skip to content

Python replace character in the list | Example code

  • by

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.3.3 (Community Edition)

Windows 10

Python 3.10.1

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

Leave a Reply

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