Home > Backend Development > Python Tutorial > 详解Python中expandtabs()方法的使用

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

WBOY
Release: 2016-06-06 11:16:52
Original
1813 people have browsed it

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

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

str.expandtabs(tabsize=8)

Copy after login

参数

  • 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);

Copy after login

当我们运行上面的程序,它会产生以下结果:

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

Copy after login

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template