Kaydet (Commit) 16fd6c46 authored tarafından Georg Brandl's avatar Georg Brandl

#1123: fix the docs for the str.split(None, sep) case.

Also expand a few other methods' docs, which had more info in the deprecated string module docs.
üst 92abad24
...@@ -686,9 +686,9 @@ string functions based on regular expressions. ...@@ -686,9 +686,9 @@ string functions based on regular expressions.
.. method:: str.count(sub[, start[, end]]) .. method:: str.count(sub[, start[, end]])
Return the number of occurrences of substring *sub* in string S\ Return the number of occurrences of substring *sub* in the range [*start*,
``[start:end]``. Optional arguments *start* and *end* are interpreted as in *end*]. Optional arguments *start* and *end* are interpreted as in slice
slice notation. notation.
.. method:: str.decode([encoding[, errors]]) .. method:: str.decode([encoding[, errors]])
...@@ -737,8 +737,11 @@ string functions based on regular expressions. ...@@ -737,8 +737,11 @@ string functions based on regular expressions.
.. method:: str.expandtabs([tabsize]) .. method:: str.expandtabs([tabsize])
Return a copy of the string where all tab characters are expanded using spaces. Return a copy of the string where all tab characters are replaced by one or
If *tabsize* is not given, a tab size of ``8`` characters is assumed. more spaces, depending on the current column and the given tab size. The
column number is reset to zero after each newline occurring in the string.
If *tabsize* is not given, a tab size of ``8`` characters is assumed. This
doesn't understand other non-printing characters or escape sequences.
.. method:: str.find(sub[, start[, end]]) .. method:: str.find(sub[, start[, end]])
...@@ -927,25 +930,29 @@ string functions based on regular expressions. ...@@ -927,25 +930,29 @@ string functions based on regular expressions.
Support for the *chars* argument. Support for the *chars* argument.
.. method:: str.split([sep [,maxsplit]]) .. method:: str.split([sep[, maxsplit]])
Return a list of the words in the string, using *sep* as the delimiter string. Return a list of the words in the string, using *sep* as the delimiter
If *maxsplit* is given, at most *maxsplit* splits are done. (thus, the list will string. If *maxsplit* is given, at most *maxsplit* splits are done (thus,
have at most ``maxsplit+1`` elements). If *maxsplit* is not specified, then the list will have at most ``maxsplit+1`` elements). If *maxsplit* is not
there is no limit on the number of splits (all possible splits are made). specified, then there is no limit on the number of splits (all possible
Consecutive delimiters are not grouped together and are deemed to delimit empty splits are made).
strings (for example, ``'1,,2'.split(',')`` returns ``['1', '', '2']``). The
*sep* argument may consist of multiple characters (for example, ``'1, 2, If *sep is given, consecutive delimiters are not grouped together and are
3'.split(', ')`` returns ``['1', '2', '3']``). Splitting an empty string with a deemed to delimit empty strings (for example, ``'1,,2'.split(',')`` returns
specified separator returns ``['']``. ``['1', '', '2']``). The *sep* argument may consist of multiple characters
(for example, ``'1<>2<>3'.split('<>')`` returns ``['1', '2', '3']``).
Splitting an empty string with a specified separator returns ``['']``.
If *sep* is not specified or is ``None``, a different splitting algorithm is If *sep* is not specified or is ``None``, a different splitting algorithm is
applied. First, whitespace characters (spaces, tabs, newlines, returns, and applied: runs of consecutive whitespace are regarded as a single separator,
formfeeds) are stripped from both ends. Then, words are separated by arbitrary and the result will contain no empty strings at the start or end if the
length strings of whitespace characters. Consecutive whitespace delimiters are string has leading or trailing whitespace. Consequently, splitting an empty
treated as a single delimiter (``'1 2 3'.split()`` returns ``['1', '2', string or a string consisting of just whitespace with a ``None`` separator
'3']``). Splitting an empty string or a string consisting of just whitespace returns ``[]``.
returns an empty list.
For example, ``' 1 2 3 '.split()`` returns ``['1', '2', '3']``, and
``' 1 2 3 '.split(None, 1)`` returns ``['1', '2 3 ']``.
.. method:: str.splitlines([keepends]) .. method:: str.splitlines([keepends])
...@@ -1035,8 +1042,10 @@ string functions based on regular expressions. ...@@ -1035,8 +1042,10 @@ string functions based on regular expressions.
.. method:: str.zfill(width) .. method:: str.zfill(width)
Return the numeric string left filled with zeros in a string of length *width*. Return the numeric string left filled with zeros in a string of length
The original string is returned if *width* is less than ``len(s)``. *width*. A sign prefix is handled correctly. The original string is
returned if *width* is less than ``len(s)``.
.. versionadded:: 2.2.2 .. versionadded:: 2.2.2
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment