expandtabs() 方法把字符串中的 tab 符号('\t')转为空格,tab 符号('\t')默认的空格数是 8。python
expandtabs()方法语法:this
str.expandtabs(tabsize=8)
该方法返回字符串中的 tab 符号('\t')转为空格后生成的新字符串。spa
如下实例展现了expandtabs()方法的实例:code
#!/usr/bin/python3 str = "this is\tstring example....wow!!!" print ("原始字符串: " + str) print ("替换 \\t 符号: " + str.expandtabs()) print ("使用16个空格替换 \\t 符号: " + str.expandtabs(16))
以上实例输出结果以下:blog
原始字符串: this is string example....wow!!! 替换 \t 符号: this is string example....wow!!! 使用16个空格替换 \t 符号: this is string example....wow!!!