Python字串rjust()方法

Python字串rjust()方法返回長度為width的字串右對齊的字串。 使用指定的fillchar(默認為空格)填充完成。 如果寬度小於len(s),則返回原始字串。

語法

以下是rjust()方法的語法 -

str.rjust(width[, fillchar])

參數

  • width -這是填充後的字串總長度。
  • fillchar - 這是用於填充的字串。

返回值

  • 返回長度為width的字串右對齊的字串。 使用指定的fillchar(默認為空格)填充完成。 如果寬度小於len(s),則返回原始字串。

示例

以下示例顯示了rjust()方法的用法 -

#!/usr/bin/python3

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

當運行上面的程式,它產生以下結果 -

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

上一篇: Python字串 下一篇: Python列表