Home >>Python String Methods >Python String expandtabs() Method
Python string expandtabs() method is used to set the tab size within the given input string to the required number of whitespaces.
Syntax:string.expandtabs(tabsize)
Parameter | Description |
---|---|
tabsize | This is an optional parameter. It defines a number specifying the tabsize. The default tabsize value is 8. |
txt = "P\tH\tP\tT\tP\tO\tI\tN\tT"
x = txt.expandtabs(2)
print(x)
txt = "H\te\tl\tl\to"
print(txt.expandtabs())
print(txt.expandtabs(2))
print(txt.expandtabs(4))
print(txt.expandtabs(10))
H e l l o H e l l o H e l l o H e l l o