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

Skip to content

Commit 638de33

Browse files
committed
Merge #15554: clarify splitlines/split differences.
Patch by Chris Jerdonek.
2 parents a0abb44 + 05c35a6 commit 638de33

1 file changed

Lines changed: 8 additions & 5 deletions

File tree

Doc/library/stdtypes.rst

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1351,16 +1351,19 @@ functions based on regular expressions.
13511351

13521352
.. method:: str.splitlines([keepends])
13531353

1354-
Return a list of the lines in the string, breaking at line boundaries. Line
1355-
breaks are not included in the resulting list unless *keepends* is given and
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.
1354+
Return a list of the lines in the string, breaking at line boundaries.
1355+
This method uses the universal newlines approach to splitting lines.
1356+
Line breaks are not included in the resulting list unless *keepends* is
1357+
given and true.
13591358

13601359
For example, ``'ab c\n\nde fg\rkl\r\n'.splitlines()`` returns
13611360
``['ab c', '', 'de fg', 'kl']``, while the same call with ``splitlines(True)``
13621361
returns ``['ab c\n', '\n, 'de fg\r', 'kl\r\n']``.
13631362

1363+
Unlike :meth:`~str.split` when a delimiter string *sep* is given, this
1364+
method returns an empty list for the empty string, and a terminal line
1365+
break does not result in an extra line.
1366+
13641367

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

0 commit comments

Comments
 (0)