Python OOPs


Examples


Others


expandtabs() method in Python


The expandtabs() method returns a string with all tab characters replaced with given tab size.

Syntax
string.expandtabs(tabsize)

Parameters

  • tabsize - (Optional) Specifying the tabsize. Default tabsize is 8.

The following example shows, how works the expandtabs() method.

Example
txt = "This\tis\tsample\ttext"
print(txt.expandtabs())
print(txt.expandtabs(2))
print(txt.expandtabs(4))
print(txt.expandtabs(6))

Output

This    is      sample  text
This  is  sample  text
This    is  sample  text
This  is    sample      text

Python String Methods