cpython: 6a02d2af814f (original) (raw)
Mercurial > cpython
changeset 83483:6a02d2af814f 2.7
Issue #17670: Provide an example of expandtabs() usage. [#17670]
Ned Deily nad@acm.org | |
---|---|
date | Sun, 21 Apr 2013 13:04:10 -0700 |
parents | c0cb78bedc2b |
children | a1421d28393b |
files | Doc/library/stdtypes.rst |
diffstat | 1 files changed, 16 insertions(+), 4 deletions(-)[+] [-] Doc/library/stdtypes.rst 20 |
line wrap: on
line diff
--- a/Doc/library/stdtypes.rst +++ b/Doc/library/stdtypes.rst @@ -931,10 +931,22 @@ string functions based on regular expres .. method:: str.expandtabs([tabsize]) Return a copy of the string where all tab characters are replaced by one or
- more spaces, depending on the current column and the given tab size. The
- column number is reset to zero after each newline occurring in the string.
- If tabsize is not given, a tab size of
8
characters is assumed. This - doesn't understand other non-printing characters or escape sequences.
- more spaces, depending on the current column and the given tab size. Tab
- positions occur every tabsize characters (default is 8, giving tab
- positions at columns 0, 8, 16 and so on). To expand the string, the current
- column is set to zero and the string is examined character by character. If
- the character is a tab (
\t
), one or more space characters are inserted - in the result until the current column is equal to the next tab position.
- (The tab character itself is not copied.) If the character is a newline
- (
\n
) or return (\r
), it is copied and the current column is reset to - zero. Any other character is copied unchanged and the current column is
- incremented by one regardless of how the character is represented when
- printed. +
>>> '01\t012\t0123\t01234'.expandtabs()[](#l1.23)
'01 012 0123 01234'[](#l1.24)
>>> '01\t012\t0123\t01234'.expandtabs(4)[](#l1.25)
'01 012 0123 01234'[](#l1.26)