Python 3 reference · String Methods
Python String expandtabs() Method
Return a copy where tab characters are replaced by spaces, aligning to tab stops every tabsize columns (8 by default).
Python 3 Since 3.0
Syntax
str.expandtabs(tabsize=8)
Parameters
| Parameter | Description |
|---|---|
tabsize optional |
Columns between tab stops. Default: 8 |
Return value
A new string.
Examples
row = "name\tage\tcity"
print(row.expandtabs())
print(row.expandtabs(6))
Output
name age city name age city
print(repr("a\tbc\tdef".expandtabs(4)))
Output
'a bc def'
Version history
| Version | Change |
|---|---|
| Python 3.0 | Added |
Related
str.ljust()· Return the string left-justified in a field of the given width, padded on the right with a fill character.str.replace()· Return a copy with every occurrence of old replaced by new, or only the first count occurrences.- Python Strings · tutorial