无涯教程-Python3 - rjust(width,[,fillchar])函数

59 阅读1分钟

Python的 rjust()方法右对齐字符串,并用fillchars填充剩余的空间。此方法返回一个右对齐的新字符串,并用fillchars填充。

rjust - 语法

rjust(width[, fillchar])

rjust - 参数

  • width    -  给定字符串的宽度。
  • fillchar  -  填充字符串剩余空间的字符。这是可选的。

rjust - 返回

它返回一个右对齐的字符串。


让无涯教程看一下rjust()方法的一些例子,以了解它的功能。

# Python rjust() method example
# 变量声明
str = Learnfk
# 调用函数
str = str.rjust(20)
# 显示结果
print(str)

输出



L e a r n f k
# Python rjust() method example
# 变量声明
str = Learnfk
# 调用函数
str = str.rjust(15,"$")
# 显示结果
print(str)

输出

$ $ $ $ $ $ $ L e a r n f k

参考链接

www.learnfk.com/python3/pyt…