# Python CodeRecipe|ljust()の使い方

Home String Methods

# ljust()の例1

Return a 20 characters long, left justified version of the word "banana":

    txt = "banana"x = txt.ljust(20)print(x, "is my 
    favorite fruit.")

Note: In the result, there are actually 14 whitespaces to the right of the word banana.

# ljust()の定義及び使い方

ljust()関数は、 指定した文字(スペースはデフォルトです)を充てん文字として使用します。

# ljust()の構文

string.ljust(length, character)

# ljust()の引数

パラメータ 説明

length 必須. The length of the returned string

character オプション. A character to fill the missing space (to the right of the string). Default is " " (space).

# ljust()の例2

Using the letter "O" as the padding character:

    txt = "banana"x = txt.ljust(20, "O")print(x)

Home String Methods