Python String expandtabs() Method

Last Updated:

Python String expandtabs()

The expandtabs() method return a copy of the string where all tab characters are expanded to the specified number of whitespaces.

Example

Python Compiler
txt = "B\ty\te" print(txt.expandtabs(2)) print(txt.expandtabs(4)) print(txt.expandtabs(6)) print(txt.expandtabs())

Syntax

txt.expandtabs(tabsize)

Parameter Values

ValueTypeExplanation
tabsize Optional Specifies the number of whitespaces to be replaced for a tab character '\t'.
Default value is 8.

Return Value

ValueExplanation
String Return a copy of the string where all tab characters are expanded to the specified number of whitespaces.

Share this Page

Meet the Author