Python3 string.rjust()方法

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!!!


上一篇: Python3数字 下一篇: Python3字符串