Python Glossary Русский

all Python 3Strings (str)function

str.expandtabs

replacement

Replace tabs with spaces, aligning to columns that are multiples of tabsize (default 8).

Syntax

s.expandtabs(tabsize=8)

A tab's width depends on the current column rather than being fixed: it stretches the text to the next multiple of tabsize, so the same character may expand to one space or to seven — replacing each tab with tabsize spaces gives a different result. The column counter resets at every newline and carriage return, so multi-line text is measured line by line.

Examples

print('a\tb'.expandtabs(4))   # → a   b
print('ab\tc'.expandtabs(4))  # → ab  c
print('a\tb'.expandtabs(1))   # → a b

See also

Open in the full glossarydocs.python.orgReport an inaccuracy