Python中expandtabs()的使用方法
发布时间:2020-08-26 18:13:03
来源:亿速云
阅读:113
作者:小新
本篇文章和大家了解一下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()的使用方法的简略介绍,当然详细使用上面的不同还得要大家自己使用过才领会。如果想了解更多,欢迎关注亿速云行业资讯频道哦!