strip doesn't mean "remove this substring". x.strip(y) treats y as a set of characters and strips any characters in that set from both ends of x.

On Python 3.9 and newer you can use the removeprefix and removesuffix methods to remove an entire substring from either side of the string:

url = 'abcdc.com'
url.removesuffix('.com')    # Returns 'abcdc'
url.removeprefix('abcdc.')  # Returns 'com'

The relevant Python Enhancement Proposal is PEP-616.

On Python 3.8 and older you can use endswith and slicing:

url = 'abcdc.com'
if url.endswith('.com'):
    url = url[:-4]

Or a regular expression:

import re
url = 'abcdc.com'
url = re.sub('\.com$', '', url)
Answer from Steef on Stack Overflow
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ python-string-removesuffix
Python String - removesuffix() - GeeksforGeeks
July 23, 2025 - This method returns a new string with the suffix removed. If the suffix is not found at the end, it returns the original string unchanged. removesuffix() method is case-sensitive, meaning it will only remove the suffix if the case matches exactly.
๐ŸŒ
Codecademy
codecademy.com โ€บ docs โ€บ python โ€บ strings โ€บ .removesuffix()
Python | Strings | .removesuffix() | Codecademy
August 28, 2025 - The str.removesuffix() method returns a new string with the specified suffix removed, if present. If the string does not end with the given suffix, the original string is returned unchanged.
๐ŸŒ
Stack Abuse
stackabuse.com โ€บ python-remove-the-prefix-and-suffix-from-a-string
Python: Remove the Prefix and Suffix From a String
March 7, 2023 - Again, we first validate the line using the endswith() method to check if the suffix is present. If this is true, the suffix is removed from the string: $ python remove_suffix_alt.py Before: xyxyxyxyxy | yzyzyzyzyz 5 After: xyxyxyxyxy | yzyzyzyz 4
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ python-remove-suffix-from-string-list
Python - Remove suffix from string list - GeeksforGeeks
July 12, 2025 - li = ['allx', 'lovex', 'gfg', 'xit', 'is', 'bestx'] # Suffix s = 'x' for word in li[:]: if word.endswith(s): li.remove(word) print(li) ... li.remove(word): This removes the word from the original list if it matches the condition, only removing ...
๐ŸŒ
Python
peps.python.org โ€บ pep-0616
PEP 616 โ€“ String methods to remove prefixes and suffixes | peps.python.org
March 19, 2020 - This is a proposal to add two new methods, removeprefix() and removesuffix(), to the APIs of Pythonโ€™s various string objects. These methods would remove a prefix or suffix (respectively) from a string, if present, and would be added to Unicode ...
๐ŸŒ
TestDriven.io
testdriven.io โ€บ tips โ€บ fe2e27db-b5ab-4f9f-b59b-472a7d9f6594
Tips and Tricks - Python - remove a suffix from a string | TestDriven.io
You can remove the suffix of a string with .removesuffix(). For example, to remove the file type from a filename:
๐ŸŒ
Note.nkmk.me
note.nkmk.me โ€บ home โ€บ python
Remove a Substring from a String in Python | note.nkmk.me
April 23, 2025 - This article explains how to remove a substring (i.e., a part of a string) from a string in Python. Contents ยท Remove a substring by replacing it with an empty string ยท Remove exact match string: replace() Remove substrings using regex: re.sub() Remove leading and/or trailing characters ยท Remove leading and trailing characters: strip() Remove leading characters: lstrip() Remove trailing characters: rstrip() Remove prefix: removeprefix() (Python 3.9 or later) Remove suffix: removesuffix() (Python 3.9 or later) Remove a substring by position and length: slicing ยท
Find elsewhere
๐ŸŒ
datagy
datagy.io โ€บ home โ€บ python posts โ€บ python strings โ€บ how to remove a prefix or suffix from a string in python
How to Remove a Prefix or Suffix from a String in Python โ€ข datagy
December 16, 2022 - How to use string slicing to remove a prefix or a suffix ... If you are using Python 3.9 or later, the best way to remove a suffix from a string in Python is to use the .removeprefix() method.
๐ŸŒ
Kieran Barker
barker.codes โ€บ blog โ€บ removing-prefixes-and-suffixes-in-python
Removing prefixes and suffixes in Python - Kieran Barker
January 16, 2023 - Not only is this more readable, ... โ‰ค 3.8, the easiest way to remove a prefix (or suffix) from a string is to check if the string starts with the prefix (or ends with the suffix) and slice it....
๐ŸŒ
Tutorialspoint
tutorialspoint.com โ€บ python โ€บ removesuffix_method.htm
Python String removesuffix() Method
The Python string removesuffix() method is used to remove a specified suffix from the end of a string. If the string ends with the specified suffix, the method removes the suffix from the string and returns the modified string.
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ article โ€บ python-program-to-delete-suffix-from-the-given-string
Python program to delete suffix from the given string
March 27, 2026 - Use string slicing with endswith() for precise suffix removal. The rstrip() method works well for character removal, while replace() is useful when combined with conditional checks. Choose the method that best fits your specific use case.
๐ŸŒ
All About AI-ML
indhumathychelliah.com โ€บ 2020 โ€บ 10 โ€บ 12 โ€บ new-string-methods-to-remove-prefixes-and-suffixes-in-python-3-9
New String Methods to Remove Prefixes and Suffixes in Python 3.9 โ€“ All About AI-ML
January 2, 2022 - removeprefix,removesuffix โ†’ only at most one copy of prefix/suffix is removed. lstrip,rstrip โ†’ the characters are repeatedly removed from the beginning/end of the string.
๐ŸŒ
Quora
quora.com โ€บ Whats-the-best-way-to-remove-a-suffix-of-a-string-in-Python
What's the best way to remove a suffix of a string in Python? - Quora
Answer (1 of 2): It depends on the suffix - If then suffix is always there, and is a fixed length - then simply use slicing : To remove the last n characters from a string : [code]the_string = the_string[:-n] [/code]If the suffix is variable length, but always has a particular set of character...
๐ŸŒ
Python Morsels
pythonmorsels.com โ€บ prefixes-and-suffixes
Checking for string prefixes and suffixes in Python - Python Morsels
August 12, 2025 - To remove a prefix or suffix, use the removeprefix or removesuffix methods. If you need to remove repeated characters from either end of a string, check out the various strip methods instead.
๐ŸŒ
Medium
medium.com โ€บ @asierr โ€บ pythons-str-removeprefix-and-str-removesuffix-finally-a-cleaner-way-to-modify-strings-468ee7114eb5
Python's str.removeprefix() and str.removesuffix(): Finally, a ...
February 18, 2025 - In this article, weโ€™ll explore what these methods do, why they were introduced, and how they can simplify your Python string manipulations. ๐Ÿš€ ... Before Python 3.9, developers had to use manual slicing or regular expressions to remove prefixes and suffixes. text = "prefix_data" if text.startswith("prefix_"): text = text[len("prefix_"):] print(text) # "data" text = "data_suffix" if text.endswith("_suffix"): text = text[:-len("_suffix")] print(text) # "data"
๐ŸŒ
Python Examples
pythonexamples.org โ€บ python-string-removesuffix
Python String removesuffix()
Since the original string "HelloWorld" does not end with the suffix value "Apple", removesuffix() returned a copy of the original string. In this tutorial of Python Examples, we learned about string removesuffix() method, and how to use this string removesuffix() method to remove the specified ...