expandtabs() String Method in Python with Examples
expandtabs()
method returns a copy of string where all tab characters are expanded using number of spaces given in argument tabsize = integer_number
.
Syntax: expandtabs() String Method
expandtabs(tabsize=integer_number)
Example: expandtabs() String Method
message = '\tWelcome to Python !'
print(message)
print(message.expandtabs(tabsize=16))
Note: here \t
is TAB and also known as escape sequence.
Output
Welcome to Python withot TAB! Welcome to Python with TAB! Welcome to Python with TAB!
Compare above three results to understand it properly & notice the gap in the begining of the output string :)
Related String Methods