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列表