Latest web development tutorials

Pythonのexpandtabs()メソッド

Python文字列 Python文字列


説明

スペースに文字列のタブ記号( '\ tの')、タブ記号( '\ tの')へのPython expandtabs()メソッドは、スペース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文字列 Python文字列