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

Skip to content

Commit 05c35a6

Browse files
committed
#15554: clarify splitlines/split differences.
Patch by Chris Jerdonek.
1 parent 9b000e7 commit 05c35a6

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
@@ -1327,16 +1327,19 @@ functions based on regular expressions.
13271327

13281328
.. method:: str.splitlines([keepends])
13291329

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

13361335
For example, ``'ab c\n\nde fg\rkl\r\n'.splitlines()`` returns
13371336
``['ab c', '', 'de fg', 'kl']``, while the same call with ``splitlines(True)``
13381337
returns ``['ab c\n', '\n, 'de fg\r', 'kl\r\n']``.
13391338

1339+
Unlike :meth:`~str.split` when a delimiter string *sep* is given, this
1340+
method returns an empty list for the empty string, and a terminal line
1341+
break does not result in an extra line.
1342+
13401343

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

0 commit comments

Comments
 (0)