From 5b052d82ca4beefa6bad77624f002fbedcbd8071 Mon Sep 17 00:00:00 2001 From: Joey Smith Date: Wed, 14 May 2025 04:17:26 -0600 Subject: [PATCH] gh-133986: Document string split algorithm when sep is None and maxsplit is 0 (GH-133987) * Document string split algorithm when sep is None and maxsplit is 0 * Update Doc/library/stdtypes.rst Co-authored-by: Semyon Moroz --------- (cherry picked from commit 3e23047363f384b7254b7af51afe4e353be94167) Co-authored-by: Joey Smith Co-authored-by: Ned Batchelder Co-authored-by: Semyon Moroz --- Doc/library/stdtypes.rst | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/Doc/library/stdtypes.rst b/Doc/library/stdtypes.rst index 0936be0caaf903..ccaa0efaada7c7 100644 --- a/Doc/library/stdtypes.rst +++ b/Doc/library/stdtypes.rst @@ -2133,6 +2133,18 @@ expression support in the :mod:`re` module). >>> ' 1 2 3 '.split() ['1', '2', '3'] + If *sep* is not specified or is ``None`` and *maxsplit* is ``0``, only + leading runs of consecutive whitespace are considered. + + For example:: + + >>> "".split(None, 0) + [] + >>> " ".split(None, 0) + [] + >>> " foo ".split(maxsplit=0) + ['foo '] + .. index:: single: universal newlines; str.splitlines method