From decdb74227c3f4d791642f1496447b99b8ac7816 Mon Sep 17 00:00:00 2001 From: R David Murray Date: Mon, 6 Aug 2012 16:09:09 -0400 Subject: [PATCH] #15554: clarify splitlines/split differences. Patch by Chris Jerdonek. --- Doc/library/stdtypes.rst | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/Doc/library/stdtypes.rst b/Doc/library/stdtypes.rst index 162b6927a83..a7a6fb11962 100644 --- a/Doc/library/stdtypes.rst +++ b/Doc/library/stdtypes.rst @@ -1183,16 +1183,19 @@ string 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]])