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

Skip to content

Commit ae1b94b

Browse files
committed
#14957: clarify splitlines docs.
Initial patch by Michael Driscoll, I added the example.
1 parent 3f7d1d3 commit ae1b94b

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

Doc/library/stdtypes.rst

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1329,7 +1329,13 @@ functions based on regular expressions.
13291329

13301330
Return a list of the lines in the string, breaking at line boundaries. Line
13311331
breaks are not included in the resulting list unless *keepends* is given and
1332-
true.
1332+
true. This method uses the universal newlines approach to splitting lines.
1333+
Unlike :meth:`~str.split`, if the string ends with line boundary characters
1334+
the returned list does ``not`` have an empty last element.
1335+
1336+
For example, ``'ab c\n\nde fg\rkl\r\n'.splitlines()`` returns
1337+
``['ab c', '', 'de fg', 'kl']``, while the same call with ``splinelines(True)``
1338+
returns ``['ab c\n', '\n, 'de fg\r', 'kl\r\n']``.
13331339

13341340

13351341
.. method:: str.startswith(prefix[, start[, end]])

0 commit comments

Comments
 (0)