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.
3 min read
Python partition vs split comes down to this: str.partition(sep) cuts once at the first separator and always returns a 3-tuple, even when the separator is missing. str.split(sep) returns a list of every piece. Use partition() for one key=value cut you want to unpack safely, and split() when you need all the parts.
We ran this on Python 3.13.5:
partition() returns a tuple of exactly three items: the part before the separator, the separator, and the rest. split() returns a list whose length depends on the input.
This is the biggest difference:
With partition() you can always unpack three names, and an empty middle value tells you the separator was not found. With split() you have to check the length first or catch the error.
They cut from the right:
Note the flip: when the separator is missing, rpartition() puts the whole string last, not first.
"=x".partition("=") gives ('', '=', 'x') and "x=".partition("=") gives ('x', '=', '')."".partition("=") gives ('', '', ''), while "".split("=") gives [''].ValueError: empty separator.TypeError: str.partition() takes exactly one argument (0 given)." a b ".split() gives ['a', 'b'], but .split(" ") gives ['', '', 'a', '', 'b', ''].b"k=v".partition(b"=") gives (b'k', b'=', b'v').Slightly, in our runs. With s = "user@example.com":
| Call | ns per call |
|---|---|
| s.partition("@") | 37.4 |
| s.split("@", 1) | 45.3 |
| s.partition("@")[2] | 40.2 |
| s.split("@", 1)[1] | 48.6 |
The gap gets big when there are many separators and you only need the first cut. On "a=" repeated 1,000 times, partition("=") took 58.7 ns, split("=", 1) took 65.9 ns, and a plain split("=") took 4,640.9 ns because it builds a list of 1,001 pieces.
Does partition() support a maxsplit?No. It always cuts exactly once. Use split(sep, maxsplit) for more control.
Does partition() accept a regex?No. Both methods take a plain string. Use re.split() for patterns.
Is partition() in Python 2?Yes, it dates back to Python 2.5. Our tests ran on Python 3.13.5.
Lab evidence
Tested on 1 Nov 2026 on our Linux box (x86_64) with Python 3.13.5. Every output below was printed by a real run, and the timings came from timeit, best of 5 runs of 1,000,000 calls each. Timings are in nanoseconds per call on this one machine, so treat them as relative, not absolute. Behaviour was cross-checked against the Python docs for str.partition, str.rpartition and str.split.
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
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
Dragging videos is the official way to change a playlist's order. Here are the steps from YouTube Help, where to find them in YouTube Studio, and the cases where reordering will not work.
Summary31 Oct 20263 min read