Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 770184b

Browse files
committed
SF bug #1105286: Undocumented implicit strip() in split(None) string method
Clarify the behavior when a string begins or ends with whitespace.
1 parent 6267996 commit 770184b

1 file changed

Lines changed: 10 additions & 6 deletions

File tree

Doc/lib/libstdtypes.tex

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -738,7 +738,9 @@ \subsubsection{String Methods \label{string-methods}}
738738
Return a list of the words in the string, using \var{sep} as the
739739
delimiter string. If \var{maxsplit} is given, at most \var{maxsplit}
740740
splits are done, the \emph{rightmost} ones. If \var{sep} is not specified
741-
or \code{None}, any whitespace string is a separator.
741+
or \code{None}, any whitespace string is a separator. Except for splitting
742+
from the right, \method{rsplit()} behaves like \method{split()} which
743+
is described in detail below.
742744
\versionadded{2.4}
743745
\end{methoddesc}
744746

@@ -765,11 +767,13 @@ \subsubsection{String Methods \label{string-methods}}
765767
separator returns an empty list.
766768

767769
If \var{sep} is not specified or is \code{None}, a different splitting
768-
algorithm is applied. Words are separated by arbitrary length strings of
769-
whitespace characters (spaces, tabs, newlines, returns, and formfeeds).
770-
Consecutive whitespace delimiters are treated as a single delimiter
771-
(\samp{'1 2 3'.split()} returns \samp{['1', '2', '3']}). Splitting an
772-
empty string returns \samp{['']}.
770+
algorithm is applied. First, whitespace characters (spaces, tabs,
771+
newlines, returns, and formfeeds) are stripped from both ends. Then,
772+
words are separated by arbitrary length strings of whitespace
773+
characters. Consecutive whitespace delimiters are treated as a single
774+
delimiter (\samp{'1 2 3'.split()} returns \samp{['1', '2', '3']}).
775+
Splitting an empty string or a string consisting of just whitespace
776+
will return \samp{['']}.
773777
\end{methoddesc}
774778

775779
\begin{methoddesc}[string]{splitlines}{\optional{keepends}}

0 commit comments

Comments
 (0)