The real rule from the Python docs, a 1-million-string test of what lstrip() breaks, and measured speed on Python 3.13.
3 min read
The removeprefix vs lstrip Python difference is simple: removeprefix('abc') removes that exact string once, and only if the text starts with it, while lstrip('abc') treats its argument as a set of characters and keeps stripping any of them from the left. Use removeprefix() for prefixes. It needs Python 3.9 or newer.
The Python docs say:
The docs' own example shows the trap:
Because it keeps going while the next character is anywhere in the set. In our run, lstrip('https:/') turned 'Open hello.com' into 'ello.com' and 'Open shop.com' into 'op.com', while removeprefix('https://') gave 'hello.com' and 'shop.com'.
We ran both over 1,000,000 random URLs whose names used the letters a to j. lstrip() gave a different, wrong result on 99,904 of them, which is every name starting with h, about 10 percent. Bugs like this slip through tests that only use friendly sample data.
In our test, yes. Python 3.13.5, 1,000,000 strings that all start with https://, best of 7 runs:
So the correct tool was also the quickest one here, and the regex workaround was the slowest.
No. It removes one copy. In our run 'aaab'.removeprefix('a') returned 'aab', while 'aaab'.lstrip('a') returned 'b'. PEP 616 lists removing multiple copies of a prefix under Rejected Ideas. If you really want every repeat gone, loop or use lstrip() on purpose.
With no argument, or None, lstrip() removes leading whitespace. removeprefix() has no default; you must pass the prefix. In our run ' pad'.lstrip() gave 'pad', but ' pad'.removeprefix(' ') gave ' pad', with only one space removed.
The same rule applies at the end of a string. The docs show 'Monty Python'.rstrip(' Python') returning 'M', while 'Monty Python'.removesuffix(' Python') returns 'Monty'. removesuffix() also returns the string unchanged when the suffix is empty.
Use the startswith() and slice pattern that PEP 616 gives as the method's specification:
Does removeprefix() work on bytes? Yes. PEP 616 added it to bytes, bytearray and collections.UserString too. In our run b'v1.2'.removeprefix(b'v') returned b'1.2'.
Is removeprefix() case-sensitive? Yes. 'Hello'.removeprefix('he') returned 'Hello' unchanged, while 'Hello'.removeprefix('He') returned 'llo'.
Can I pass a tuple of prefixes? No. Passing a tuple raised TypeError: removeprefix() argument must be str, not tuple. PEP 616 rejected accepting a tuple of affixes.
Lab evidence
Checked on 22 Oct 2026 against the official Python docs for str.removeprefix(), str.lstrip(), str.rstrip() and str.removesuffix(), and PEP 616. We ran a real benchmark and behaviour checks on 22 Oct 2026 with Python 3.13.5 on an 8-vCPU x86_64 Linux box: 1,000,000 seeded random strings with an https:// prefix, best of 7 runs with timeit. Timings are from that one machine and will differ on yours; Python versions before 3.9 were not tested.
Explore the product
Freelancers and devs who want to turn coding skills into paid site builds
We ran three typescript-eslint presets on a real open-source TypeScript library and counted every finding and second. The jump to strict was smaller than the jump to type-aware linting, and the findings themselves tell you whether your team is ready.
Summary4 Nov 20267 min read
Both cut a string at a separator, but they fail in different ways. We ran them on Python 3.13.5 to show where partition() is safer and where split() is the right tool.
Summary2 Nov 20263 min read
What changes when you swap sort() for toSorted(), with a real 1-million-item Node.js benchmark and the support table.
Summary1 Nov 20263 min read