Python3 rjust()メソッド

Python3 字符串Python3 文字列


説明

rjust() は、元の文字列を右寄せし、スペースで埋めて長さ width の新しい文字列を返します。指定された長さが文字列の長さより小さい場合は、元の文字列を返します。

構文

rjust()メソッドの構文:

str.rjust(width[, fillchar])

パラメータ

  • width -- 指定した文字で埋めた後の文字列の全体の長さを指定します。
  • fillchar -- 埋める文字。デフォルトはスペースです。

戻り値

元の文字列を右寄せし、スペースで埋めて長さ width の新しい文字列を返します。指定された長さが文字列の長さより小さい場合は、元の文字列を返します。

例

以下の例は、rjust()関数の使用方法を示しています:

#!/usr/bin/python3

str = "this is string example....wow!!!"
print (str.rjust(50, '*'))

上記の例の出力結果は次のとおりです:

******************this is string example....wow!!!

Python3 字符串Python3 文字列

その他の拡張