Python String rjust()メソッド
例
「バナナ」という単語の20文字の長さの右寄せバージョンを返します。
txt = "banana"
x = txt.rjust(20)
print(x, "is my
favorite fruit.")
注:結果として、バナナという単語の左側には実際には14個の空白があります。
定義と使用法
このrjust()
メソッドは、指定された文字(スペースがデフォルト)を塗りつぶし文字として使用して、文字列を右揃えにします。
構文
string.rjust(length, character)
パラメータ値
Parameter | Description |
---|---|
length | Required. The length of the returned string |
character | Optional. A character to fill the missing space (to the left of the string). Default is " " (space). |
その他の例
例
パディング文字として文字「O」を使用する:
txt = "banana"
x = txt.rjust(20, "O")
print(x)