Python 3 – expandtabs() method for strings
Python 3 – String expandtabs() Method
Description
expandtabs() method returns a copy of a string with tab characters (i.e., ‘t’) expanded with spaces, optionally using a given tab size (default is 8).
Syntax
Following is the syntax of the expandtabs() method −
str.expandtabs(tabsize = 8)
Parameters
tabsize − This specifies the number of characters to replace the tab character ‘t’ with.
Return Value
This method returns a copy of the string with tab characters (‘t’) expanded with spaces.
Example
#!/usr/bin/python3
str = "this iststring example....wow!!!"
print ("Original string: " + str)
print ("Defualt exapanded tab: " + str.expandtabs())
print ("Double exapanded tab: " + str.expandtabs(16))
Result
After running the above program, the following result will be produced −
Original string: this is string example....wow!!!
Defualt exapanded tab: this is string example....wow!!!
Double exapanded tab: this is string example....wow!!!