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 字串