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

Skip to content

Commit 5a0d439

Browse files
committed
#14957: clarify splitlines docs.
Initial patch by Michael Driscoll, I added the example.
2 parents be1bc8c + ae1b94b commit 5a0d439

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
@@ -1353,7 +1353,13 @@ functions based on regular expressions.
13531353

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

13581364

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

0 commit comments

Comments
 (0)