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

Skip to content

Commit bebe91a

Browse files
committed
Issue #17670: Provide an example of expandtabs() usage.
1 parent 4140fb5 commit bebe91a

1 file changed

Lines changed: 17 additions & 5 deletions

File tree

Doc/library/stdtypes.rst

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1526,11 +1526,23 @@ expression support in the :mod:`re` module).
15261526

15271527
.. method:: str.expandtabs([tabsize])
15281528

1529-
Return a copy of the string where all tab characters are replaced by zero or
1530-
more spaces, depending on the current column and the given tab size. The
1531-
column number is reset to zero after each newline occurring in the string.
1532-
If *tabsize* is not given, a tab size of ``8`` characters is assumed. This
1533-
doesn't understand other non-printing characters or escape sequences.
1529+
Return a copy of the string where all tab characters are replaced by one or
1530+
more spaces, depending on the current column and the given tab size. Tab
1531+
positions occur every *tabsize* characters (default is 8, giving tab
1532+
positions at columns 0, 8, 16 and so on). To expand the string, the current
1533+
column is set to zero and the string is examined character by character. If
1534+
the character is a tab (``\t``), one or more space characters are inserted
1535+
in the result until the current column is equal to the next tab position.
1536+
(The tab character itself is not copied.) If the character is a newline
1537+
(``\n``) or return (``\r``), it is copied and the current column is reset to
1538+
zero. Any other character is copied unchanged and the current column is
1539+
incremented by one regardless of how the character is represented when
1540+
printed.
1541+
1542+
>>> '01\t012\t0123\t01234'.expandtabs()
1543+
'01 012 0123 01234'
1544+
>>> '01\t012\t0123\t01234'.expandtabs(4)
1545+
'01 012 0123 01234'
15341546

15351547

15361548
.. method:: str.find(sub[, start[, end]])

0 commit comments

Comments
 (0)