Python中expandtabs()的使用方法-创新互联

创新互联www.cdcxhl.cn八线动态BGP香港云服务器提供商,新人活动买多久送多久,划算不套路!

创新互联从2013年成立,是专业互联网技术服务公司,拥有项目网站制作、做网站网站策划,项目实施与项目整合能力。我们以让每一个梦想脱颖而出为使命,1280元曲周做网站,已为上家服务,为曲周各地企业和个人服务,联系电话:028-86922220

本篇文章和大家了解一下Python中expandtabs()的使用方法。有一定的参考价值,有需要的朋友可以参考一下,希望对大家有所帮助。

描述

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

语法

expandtabs()方法语法:

string.expandtabs(tabsize=8)

参数

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

返回值

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

实例

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

#!/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)

以上实例输出结果如下

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

以上就是Python中expandtabs()的使用方法的简略介绍,当然详细使用上面的不同还得要大家自己使用过才领会。如果想了解更多,欢迎关注创新互联-成都网站建设公司行业资讯频道哦!


网站栏目:Python中expandtabs()的使用方法-创新互联
当前地址:http://ybzwz.com/article/hesdd.html