Python string expandtabs () method

Python string expandtabs()method returns a copy of a string, tabcharacter. Expansion spaces ' \t', optionally using a given tab size - tabize(default value 8).

grammar:str.expandtabs(tabsize = 8)

Parameters: TabSize - This specifies a replacement character " \t " Number of characters to be replaced.

Returns: This method returns a copy of a string, use the space expands, " \t" character.

Example: The following example shows expandtabs()the use of the method.

>>>s = "a\tbcd\tefg\n1\t23400000000000000000000\t567"
>>>print(s)
a	bcd	efg
1	23400000000000000000000	567
>>>print(s.expandtabs())
a       bcd     efg
1       23400000000000000000000 567
>>>print(s.expandtabs(20))
a                   bcd                 efg
1                   23400000000000000000000                 567
>>>print(s.expandtabs(30))
a                             bcd                           efg
1                             23400000000000000000000       567

  

Guess you like

Origin www.cnblogs.com/ilyou2049/p/11110547.html