mirror of
https://github.com/python/cpython.git
synced 2025-09-26 10:19:53 +00:00
SF bug #1105286: Undocumented implicit strip() in split(None) string method
Clarify the behavior when a string begins or ends with whitespace.
This commit is contained in:
parent
62679968be
commit
770184b365
1 changed files with 10 additions and 6 deletions
|
@ -738,7 +738,9 @@ The original string is returned if
|
||||||
Return a list of the words in the string, using \var{sep} as the
|
Return a list of the words in the string, using \var{sep} as the
|
||||||
delimiter string. If \var{maxsplit} is given, at most \var{maxsplit}
|
delimiter string. If \var{maxsplit} is given, at most \var{maxsplit}
|
||||||
splits are done, the \emph{rightmost} ones. If \var{sep} is not specified
|
splits are done, the \emph{rightmost} ones. If \var{sep} is not specified
|
||||||
or \code{None}, any whitespace string is a separator.
|
or \code{None}, any whitespace string is a separator. Except for splitting
|
||||||
|
from the right, \method{rsplit()} behaves like \method{split()} which
|
||||||
|
is described in detail below.
|
||||||
\versionadded{2.4}
|
\versionadded{2.4}
|
||||||
\end{methoddesc}
|
\end{methoddesc}
|
||||||
|
|
||||||
|
@ -765,11 +767,13 @@ multiple characters (for example, \samp{'1, 2, 3'.split(', ')} returns
|
||||||
separator returns an empty list.
|
separator returns an empty list.
|
||||||
|
|
||||||
If \var{sep} is not specified or is \code{None}, a different splitting
|
If \var{sep} is not specified or is \code{None}, a different splitting
|
||||||
algorithm is applied. Words are separated by arbitrary length strings of
|
algorithm is applied. First, whitespace characters (spaces, tabs,
|
||||||
whitespace characters (spaces, tabs, newlines, returns, and formfeeds).
|
newlines, returns, and formfeeds) are stripped from both ends. Then,
|
||||||
Consecutive whitespace delimiters are treated as a single delimiter
|
words are separated by arbitrary length strings of whitespace
|
||||||
(\samp{'1 2 3'.split()} returns \samp{['1', '2', '3']}). Splitting an
|
characters. Consecutive whitespace delimiters are treated as a single
|
||||||
empty string returns \samp{['']}.
|
delimiter (\samp{'1 2 3'.split()} returns \samp{['1', '2', '3']}).
|
||||||
|
Splitting an empty string or a string consisting of just whitespace
|
||||||
|
will return \samp{['']}.
|
||||||
\end{methoddesc}
|
\end{methoddesc}
|
||||||
|
|
||||||
\begin{methoddesc}[string]{splitlines}{\optional{keepends}}
|
\begin{methoddesc}[string]{splitlines}{\optional{keepends}}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue