Remove the substring from the end of the string using Slicing
In this method, we are using string slicing to remove the substring from the end.
Python3
text = 'w3wikiWorld' sub = "World" # find len of suffix le = len (sub) # slice out from string text = text[: - le] print (text) |
Output:
w3wiki
Python | Remove the given substring from end of string
Sometimes we need to manipulate our string to remove extra information from the string for better understanding and faster processing. Given a task in which the substring needs to be removed from the end of the string using Python.