Languages
[Edit]
EN

Python - remove substring from string between indexes

0 points
Created by:
Meredith-Soto
325

In this article, we would like to show you how to remove substring from the string in Python.

Quick solution:

text = "ABC"
text = text.replace("B", "")
print("after: ", text)  # AC

 

Practical example

In this example, we use replace() method to remove substring from the string.

text = "ABC"

print("String before:", text)

# remove last 3 characters from a string
text = text.replace("B", "")

print("String after: ", text)

Output:

String before: ABC
String after:  AC

Note:

You can also use removeprefix() and removesuffix() method to remove substring from the beginning or the end of the string.

Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.

Cross technology - remove substring from string between indexes

Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join