目录

rjust(width,[, fillchar])

描述 (Description)

方法rjust()以长度width的字符串返回右对齐的字符串。 使用指定的fillchar完成填充(默认为空格)。 如果width小于len(s),则返回原始字符串。

语法 (Syntax)

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

str.rjust(width[, fillchar])

参数 (Parameters)

  • width - 这是填充后的字符串长度。

  • fillchar - 这是填充字符,默认是空格。

返回值 (Return Value)

此方法返回以长度宽度的字符串右对齐的字符串。 使用指定的fillchar完成填充(默认为空格)。 如果width小于len(s),则返回原始字符串。

例子 (Example)

以下示例显示了rjust()方法的用法。

#!/usr/bin/python
str = "this is string example....wow!!!";
print str.rjust(50, '0')

当我们运行上面的程序时,它产生以下结果 -

000000000000000000this is string example....wow!!!
↑回到顶部↑
WIKI教程 @2018