Home / Python / Reference / String methods

Python string removesuffix() method

Remove some text from the end, if it is there.

Syntax

str.removesuffix(suffix)

Parameters

suffixthe text to remove

Return value

str

Example

Code

print("report.csv".removesuffix(".csv"))
print("report.txt".removesuffix(".csv"))

Output

report
report.txt

Related

Learn it step by step in the free lesson Strings, with exercises that check your answers.