Python .removesuffix()
Anonymous contributor
Published Aug 28, 2025
Contribute to Docs
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. This method is case-sensitive and does not modify the original string.
Syntax
string_name.removesuffix(suffix)
Parameters:
suffix: The string to remove from the end of the original string.
Return value:
A new string with the suffix removed if it exists, otherwise, the original string.
Example 1: Removing a file extension
This method can be used to remove a file extension when the suffix matches exactly:
file_type = "Cat Store.docx"result = file_type.removesuffix('.docx')print(result)
The output would look like this:
Cat Store
Example 2: Case sensitivity
.removesuffix() is case-sensitive, so, if the case does not match exactly, the suffix is not removed:
statement = "And when I silently snuck up on my mom, I jumped up and exclaimed 'BOO!'"result = statement.removesuffix('Boo!')print(result)
Here’s the output:
And when I silently snuck up on my mom, I jumped up and exclaimed 'BOO!'
Example 3: Removing text from a sentence
The suffix must match the exact ending of the string, including punctuation:
quote = 'Do or do not, there is no try (Yoda).'result = quote.removesuffix(' (Yoda).')print(result)
The output for this code would look like this:
Do or do not, there is no try
All contributors
- Anonymous contributor
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.
Learn Python on Codecademy
- Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!
- Includes 6 Courses
- With Professional Certification
- Beginner Friendly.75 hours
- Learn the basics of Python 3.12, one of the most powerful, versatile, and in-demand programming languages today.
- With Certificate
- Beginner Friendly.24 hours