Chapters
Python114 chapters

ReferenceString methods

str.removeprefix()

Drops an exact prefix if it is there, and leaves the string alone if not.

Signature

text.removeprefix(prefix)

Parameters

NameMeans
prefixthe exact text to remove from the start

Returns

A new string.

Example

Python
print("www.example.com".removeprefix("www."))
print("example.com".removeprefix("www."))

Output

example.com
example.com

See also