How to remove parts of string in Python

Here's an example how to remove a substring from a string. It utilizes the replace function of the Python string.

str = 'something something <remove> something </removealso> yeah! <remove>'
str = str.replace('<remove>', '')
str = str.replace('</removealso>', '')
print(str)



You can do it also like this:

str = 'something something <remove> something </removealso> yeah! <remove>'
str = str.replace('<remove>', '').replace('</removealso>', '')
print(str)


Comments

Popular posts from this blog

python - random integer examples