这篇教程Python3 expandtabs()方法写得很实用,希望能帮到您。 描述expandtabs() 方法把字符串中的 tab 符号('/t')转为空格,tab 符号('/t')默认的空格数是 8。 语法expandtabs()方法语法: str.expandtabs(tabsize=8) 参数- tabsize -- 指定转换字符串中的 tab 符号('/t')转为空格的字符数。
返回值该方法返回字符串中的 tab 符号('/t')转为空格后生成的新字符串。 实例以下实例展示了expandtabs()方法的实例: #!/usr/bin/python3str = "this is/tstring example....wow!!!"print ("原始字符串: " + str)print ("替换 //t 符号: " + str.expandtabs())print ("使用16个空格替换 //t 符号: " + str.expandtabs(16)) 以上实例输出结果如下: 原始字符串: this is string example....wow!!!替换 /t 符号: this is string example....wow!!!使用16个空格替换 /t 符号: this is string example....wow!!! Python3 endswith()方法 Python3 find()方法 |