Skip to content

Commit bc4cd91

Browse files
[3.13] Update example of str.split, bytes.split (GH-121287) (#121415)
Update example of str.split, bytes.split (GH-121287) In `{str,bytes}.strip(chars)`, multiple characters are not treated as a prefix/suffix, but as individual characters. This may make users confuse whether `split` has similar behavior. Users may incorrectly expect that `'Good morning, John.'.split(', .') == ['Good', 'morning', 'John']` Adding a bit of clarification in the doc. (cherry picked from commit 892e3a1) Co-authored-by: Yuxin Wu <[email protected]> Co-authored-by: Yuxin Wu <[email protected]>
1 parent 3c3f9a2 commit bc4cd91

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

Doc/library/stdtypes.rst

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2095,8 +2095,9 @@ expression support in the :mod:`re` module).
20952095
If *sep* is given, consecutive delimiters are not grouped together and are
20962096
deemed to delimit empty strings (for example, ``'1,,2'.split(',')`` returns
20972097
``['1', '', '2']``). The *sep* argument may consist of multiple characters
2098-
(for example, ``'1<>2<>3'.split('<>')`` returns ``['1', '2', '3']``).
2099-
Splitting an empty string with a specified separator returns ``['']``.
2098+
as a single delimiter (to split with multiple delimiters, use
2099+
:func:`re.split`). Splitting an empty string with a specified separator
2100+
returns ``['']``.
21002101

21012102
For example::
21022103

@@ -2106,6 +2107,8 @@ expression support in the :mod:`re` module).
21062107
['1', '2,3']
21072108
>>> '1,2,,3,'.split(',')
21082109
['1', '2', '', '3', '']
2110+
>>> '1<>2<>3<4'.split('<>')
2111+
['1', '2', '3<4']
21092112

21102113
If *sep* is not specified or is ``None``, a different splitting algorithm is
21112114
applied: runs of consecutive whitespace are regarded as a single separator,
@@ -3149,10 +3152,9 @@ produce new objects.
31493152
If *sep* is given, consecutive delimiters are not grouped together and are
31503153
deemed to delimit empty subsequences (for example, ``b'1,,2'.split(b',')``
31513154
returns ``[b'1', b'', b'2']``). The *sep* argument may consist of a
3152-
multibyte sequence (for example, ``b'1<>2<>3'.split(b'<>')`` returns
3153-
``[b'1', b'2', b'3']``). Splitting an empty sequence with a specified
3154-
separator returns ``[b'']`` or ``[bytearray(b'')]`` depending on the type
3155-
of object being split. The *sep* argument may be any
3155+
multibyte sequence as a single delimiter. Splitting an empty sequence with
3156+
a specified separator returns ``[b'']`` or ``[bytearray(b'')]`` depending
3157+
on the type of object being split. The *sep* argument may be any
31563158
:term:`bytes-like object`.
31573159

31583160
For example::
@@ -3163,6 +3165,8 @@ produce new objects.
31633165
[b'1', b'2,3']
31643166
>>> b'1,2,,3,'.split(b',')
31653167
[b'1', b'2', b'', b'3', b'']
3168+
>>> b'1<>2<>3<4'.split(b'<>')
3169+
[b'1', b'2', b'3<4']
31663170

31673171
If *sep* is not specified or is ``None``, a different splitting algorithm
31683172
is applied: runs of consecutive ASCII whitespace are regarded as a single

0 commit comments

Comments
 (0)