发布于 2015-06-21 10:37:51 | 102 次阅读 | 评论: 0 | 来源: 网络整理

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

语法

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


str.expandtabs(tabsize=8)

参数

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

返回值

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

例子

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


#!/usr/bin/python

str = "this iststring 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!!!
最新网友评论  共有(0)条评论 发布评论 返回顶部

Copyright © 2007-2017 PHPERZ.COM All Rights Reserved   冀ICP备14009818号  版权声明  广告服务