ShopperCove
Menu
All writingBlogTopicsCategoriesAboutRSS
Blog
Categories
Observability & SRE62All categories
Topics
sre111localhost lab102performance70python58javascript47bundle size36benchmarking35node.js35web development21typescript19benchmark16content creation15All topics
About
Loading article…

ShopperCove

Hands-on notes on developer tools, written after the tool has actually been run.

All writingBlogCategoriesTopicsAboutPrivacyRSS

© 2026 ShopperCove

On this page

  1. What does each method return?
  2. What happens when the separator is missing?
  3. How do rpartition and rsplit differ?
  4. Which edge cases surprise people?
  5. Is partition faster than split?
  6. Which one should you use?
  7. FAQ
  8. Related
  9. Sources
  1. Blog

Python partition vs split: Which One Should You Use?

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.

2 November 2026·3 min read

Summary

Disclosure

This post contains affiliate links. If you buy through them, I may earn a commission at no extra cost to you. I only make firsthand claims about products I have actually used.

On this page
  1. What does each method return?
  2. What happens when the separator is missing?
  3. How do rpartition and rsplit differ?
  4. Which edge cases surprise people?
  5. Is partition faster than split?
  6. Which one should you use?
  7. FAQ
  8. Related
  9. Sources

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.

What does each method return?

We ran this on Python 3.13.5:

"key=value".partition("=")   # ('key', '=', 'value')
"key=value".split("=", 1)    # ['key', 'value']
"key=a=b".partition("=")     # ('key', '=', 'a=b')
"key=a=b".split("=")         # ['key', 'a', 'b']

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.

What happens when the separator is missing?

This is the biggest difference:

"novalue".partition("=")   # ('novalue', '', '')
"novalue".split("=")       # ['novalue']
k, _, v = "novalue".partition("=")   # works: k='novalue', v=''
k, v = "novalue".split("=", 1)
# ValueError: not enough values to unpack (expected 2, got 1)

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.

How do rpartition and rsplit differ?

They cut from the right:

"key=a=b".rpartition("=")   # ('key=a', '=', 'b')
"key=a=b".rsplit("=", 1)    # ['key=a', 'b']
"novalue".rpartition("=")   # ('', '', 'novalue')

Note the flip: when the separator is missing, rpartition() puts the whole string last, not first.

Which edge cases surprise people?

  • "=x".partition("=") gives ('', '=', 'x') and "x=".partition("=") gives ('x', '=', '').
  • "".partition("=") gives ('', '', ''), while "".split("=") gives [''].
  • An empty separator fails for both: ValueError: empty separator.
  • partition() needs an argument. Calling it bare raises TypeError: str.partition() takes exactly one argument (0 given).
  • Only split() has a no-argument mode: " a b ".split() gives ['a', 'b'], but .split(" ") gives ['', '', 'a', '', 'b', ''].
  • Both work on bytes: b"k=v".partition(b"=") gives (b'k', b'=', b'v').

Is partition faster than split?

Slightly, in our runs. With s = "user@example.com":

Callns 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.

Which one should you use?

  • One cut, like key=value, user@host or a header line: partition(), or split(sep, 1) if you want a list.
  • Last cut, like a file extension: rpartition().
  • Every piece, like CSV-ish fields or words: split().
  • Whitespace-separated words: split() with no argument.

FAQ

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.

Related

  • removeprefix vs lstrip in Python
  • Python isdigit vs isnumeric
  • csv.reader vs split lab

Sources

  • 01docs.python.org/3/library/stdtypes.html
  • 02docs.python.org/3/library/stdtypes.html
  • 03docs.python.org/3/library/stdtypes.html

Lab evidence

What I found running this

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

Turn your Python parsing skills into paid client work

See Ready Client Sites

Notes when a lab post goes up

Occasional email for new hands-on reviews. No sequence and no sponsors.

Explore the product

Freelancers and devs who want to turn coding skills into paid site builds

Turn your Python parsing skills into paid client work

See Ready Client Sites

Keep reading

  • Is typescript-eslint Strict Worth 4x Errors?

    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

  • toSorted vs sort JavaScript: Which One Copies Your Array?

    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

  • How to Reorder a YouTube Playlist, and Why Won't It Drag?

    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