String Methods

str.removeprefix()

Remove exactly one matching nonempty literal prefix from the corresponding end of the text. If it is absent or empty, return unchanged text. Unlike strip methods, the argument is an ordered substring rather than a set of removable characters. Matching is case-sensitive. The original string is unchanged.

Formal Syntax & Structure

python syntaxpython
text.removeprefix(prefix, /)

Parameters & Attributes

NameTypeDescription
prefixstrExact literal substring to remove once.

Return Value

str

Text with one matching boundary substring removed, or unchanged text.

Working Example

Example Snippetpython
print("pre-pre-item-end-end".removeprefix('pre-'))print("item".removeprefix('pre-'))
Python Reference