Python - String expandtabs() Method


Advertisements

The string expandtabs() method is used to set the tab size within the specified string. This method has one optional parameter which is used to specify the tab size. Default value of tab size is 8 whitespaces.

Syntax


string.expandtabs(tabsize)

Parameters

tabsize Optional. specify tab size. default value is 8.

Example:

In the below example, expandtabs() is used to set the tab size of the specified string.

MyString = "x\ty\tz"

print(MyString)
print(MyString.expandtabs())
print(MyString.expandtabs(1))
print(MyString.expandtabs(4))
print(MyString.expandtabs(10))

Output

x	y	z

x       y       z

x y z

x   y   z

x         y         z

String Methods
Advertisements