教程集 www.jiaochengji.com
教程集 >  Python编程  >  Python入门  >  正文 Python expandtabs()方法

Python expandtabs()方法

发布时间:2021-12-11   编辑:jiaochengji.com
教程集为您提供Python expandtabs()方法等资源,欢迎您收藏本站,我们将为您提供最新的Python expandtabs()方法资源

描述

Python expandtabs() 方法把字符串中的 tab 符号('\t')转为空格,默认的空格数 tabsize 是 8。

语法

expandtabs()方法语法:

<pre class="brush:html;toolbar:false">string.expandtabs(tabsize=8)</pre>

参数

tabsize -- 指定转换字符串中的 tab 符号('\t')转为空格的字符数。

返回值

该方法返回字符串中的 tab 符号('\t')转为空格后生成的新字符串。

实例

以下实例展示了expandtabs()方法的实例:

<pre class="brush:html;toolbar:false">#!/usr/bin/python   string = "this is\tstring example....wow!!!";   print "Original string: "   string print "Defualt exapanded tab: "    string.expandtabs() print "Double exapanded tab: "    string.expandtabs(16)</pre>

以上实例输出结果如下

<pre class="brush:html;toolbar:false">Original string: this is        string example....wow!!! Defualt exapanded tab: this is string example....wow!!! Double exapanded tab: this is         string example....wow!!!</pre>

您可能感兴趣的文章:
Python expandtabs()方法
Python dir()和help()帮助函数
python如何查看类的函数
Python字符串大小写转换的函数及用法
python 怎么查看函数的用法
linux怎么查看python的安装路径
找不到python安装路径怎么办
linux如何看Python版本
python中pip更新失败怎么办
怎样在linux上执行python程序

[关闭]
~ ~