diff options
author | R David Murray <rdmurray@bitdance.com> | 2012-08-06 20:08:09 (GMT) |
---|---|---|
committer | R David Murray <rdmurray@bitdance.com> | 2012-08-06 20:08:09 (GMT) |
commit | 05c35a6a6b62f9037ec15e5e60d5e17563adb128 (patch) | |
tree | 5a87cb12dc3f400dddb4fa81199ee240d5a909af /Doc | |
parent | 9b000e7a6835e8f1899276be1d2dfebb651ce42b (diff) | |
download | cpython-05c35a6a6b62f9037ec15e5e60d5e17563adb128.zip cpython-05c35a6a6b62f9037ec15e5e60d5e17563adb128.tar.gz cpython-05c35a6a6b62f9037ec15e5e60d5e17563adb128.tar.bz2 |
#15554: clarify splitlines/split differences.
Patch by Chris Jerdonek.
Diffstat (limited to 'Doc')
-rw-r--r-- | Doc/library/stdtypes.rst | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/Doc/library/stdtypes.rst b/Doc/library/stdtypes.rst index b2381e6..62c4436 100644 --- a/Doc/library/stdtypes.rst +++ b/Doc/library/stdtypes.rst @@ -1327,16 +1327,19 @@ functions based on regular expressions. .. method:: str.splitlines([keepends]) - Return a list of the lines in the string, breaking at line boundaries. Line - breaks are not included in the resulting list unless *keepends* is given and - true. This method uses the universal newlines approach to splitting lines. - Unlike :meth:`~str.split`, if the string ends with line boundary characters - the returned list does ``not`` have an empty last element. + Return a list of the lines in the string, breaking at line boundaries. + This method uses the universal newlines approach to splitting lines. + Line breaks are not included in the resulting list unless *keepends* is + given and true. For example, ``'ab c\n\nde fg\rkl\r\n'.splitlines()`` returns ``['ab c', '', 'de fg', 'kl']``, while the same call with ``splitlines(True)`` returns ``['ab c\n', '\n, 'de fg\r', 'kl\r\n']``. + Unlike :meth:`~str.split` when a delimiter string *sep* is given, this + method returns an empty list for the empty string, and a terminal line + break does not result in an extra line. + .. method:: str.startswith(prefix[, start[, end]]) |