Python String expandtabs() Method

Example

Set the tab size to 2 spaces:

txt = "H\te\tl\tl\to"
x = txt.expandtabs(2)
print(x)

Run Instance

Definition and Usage

The expandtabs() method sets the size of the tab to the specified number of spaces.

Syntax

string.exandtabs(tabsize)

Parameter Value

Parameter Description
tabsize Optional. Specify the number of spaces for tab size. The default tabsize is 8.

More Examples

Example

Please see the results of different tab sizes:

txt = "H\te\tl\tl\to"
print(txt)
print(txt.expandtabs())
print(txt.expandtabs(2))
print(txt.expandtabs(4))
print(txt.expandtabs(10))

Run Instance