expandtabs()方法返回制表符,即该字符串的一个副本。 \’\\t\’已经使用的空间,可选择使用给定的tabsize(默认8)扩展。
语法

以下是expandtabs()方法的语法:

str.expandtabs(tabsize=8)

参数

  •     tabsize — 此选项指定要替换为制表符“\\t\’ 的字符数.

返回值

此方法返回在制表符,即通过空格进行了扩展字符串,\’\\t\’的副本。
例子

下面的例子显示expandtabs()方法的使用。

#!/usr/bin/python

str = \"this is\\tstring example....wow!!!\";


print \"Original string: \" + str;
print \"Defualt exapanded tab: \" + str.expandtabs();
print \"Double exapanded tab: \" + str.expandtabs(16);

当我们运行上面的程序,它会产生以下结果:

Original string: this is    string example....wow!!!
Defualt exapanded tab: this is string example....wow!!!
Double exapanded tab: this is     string example....wow!!!