首页 > 编程语言 > 详细

详解Python中expandtabs()方法的使用

时间:2015-12-07 22:01:08      阅读:320      评论:0      收藏:0      [点我收藏+]

 expandtabs()方法返回制表符,即该字符串的一个副本。 ‘\t‘已经使用的空间,可选择使用给定的tabsize(默认8)扩展。
语法

以下是expandtabs()方法的语法:

str.expandtabs(tabsize=8)

参数

  •     tabsize -- 此选项指定要替换为制表符“\t‘ 的字符数.

返回值

此方法返回在制表符,即通过空格进行了扩展字符串,‘\t‘的副本。
例子

下面的例子显示expandtabs()方法的使用。

#!/usr/bin/python

str = "this is\tstring example....wow!!!";


print "Original string: " + str;
print "Defualt exapanded tab: " + str.expandtabs();
print "Double exapanded tab: " + str.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()方法的使用

原文:http://www.jb51.net/article/66269.htm

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!