Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / Python

str.removeprefix

Removes one exact prefix when it is present.

Version: Python 3.14; repository image, production runtime not attested

Syntax

s.removeprefix(prefix)

Removes one exact prefix when it is present.

Only one occurrence is removed and a missing prefix leaves the text unchanged.

The exact leading log- is removed once from log-log-data, leaving log-data. When data has no such prefix, the complete original text is retained. It does not repeatedly peel the same prefix.

assert "ababX".removeprefix("ab") == "abX" and "X".removeprefix("") == "X"

Examples

print("log-log-data".removeprefix("log-"))
print("data".removeprefix("log-"))

Result

log-data
data

The exact leading log- is removed once from log-log-data, leaving log-data. When data has no such prefix, the complete original text is retained. It does not repeatedly peel the same prefix.

Sources