Python3 string.expandtabs()方法

它返回制表符字符,即字符串的副本。 “\t”使用空格,可以选择使用给定的tabsize(默认8)扩展。

语法

str.expandtabs(tabsize=8)

参数

  • tabsize -- 指定要替换为制表符 '\t' 的字符数

  • 返回值

  • 此方法返回字符串的一个副本,制表符字符,即 '\t' 已经使用空格扩展。

示例

#!/usr/bin/python3

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!!!

上一篇: Python3数字 下一篇: Python3字符串