Latest web development tutorials

python3 expandtabs()メソッド

python3文字列 python3文字列


説明

スペースに文字列のタブ記号( '\ tの')、タブ記号( '\ tの')にexpandtabs()メソッドは、スペース8のデフォルト数です。

文法

expandtabs()メソッドの構文:

str.expandtabs(tabsize=8)

パラメータ

  • tabsize - スペース文字に変換する文字列]タブ記号( '\ tを')を指定します。

戻り値

新しい文字列の生成方法は、後のスペースに文字列]タブ記号( '\ tを')を返します。

次の例では、expandtabsの例()メソッドを示しています。

#!/usr/bin/python3

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

print ("原始字符串: " + str)
print ("替换 \\t 符号: " +  str.expandtabs())
print ("使用16个空格替换 \\t 符号: " +  str.expandtabs(16))

次のように上記の出力結果の例は次のとおりです。

原始字符串: this is     string example....wow!!!
替换 \t 符号: this is string example....wow!!!
使用16个空格替换 \t 符号: this is         string example....wow!!!

python3文字列 python3文字列