Python:文字列の中央揃え、左端揃え、右端揃え

スポンサーリンク

文字列の中央揃え、左端揃え、右端揃え

文字列のレイアウトを操作する関数(center(), ljust(), rjust())は、指定したスペースのなかで文字列をどのように配置するか決めることができます。

>>> tmp = 'this is a pen.'
>>> tmp.center(30)
'        this is a pen.        '
>>> tmp.ljust(30)
'this is a pen.                '
>>> tmp.rjust(30)
'                this is a pen.'