📜  Python字符串 rjust() 方法

📅  最后修改于: 2022-05-13 01:54:41.978000             🧑  作者: Mango

Python字符串 rjust() 方法

Python String rjust() 方法在替换原始字符串左侧的给定字符后返回给定长度的新字符串。

示例 1

Python3
# Python program to demonstrate working of
# rjust()
string = 'geeks'
length = 8
  
# If no fill character is provided, space
# is used as fill character
print(string.rjust(length))


Python3
# example string
string = 'geeks'
length = 8
fillchar = '*'
  
print(string.rjust(length, fillchar))


输出:

geeks 

示例 2

蟒蛇3

# example string
string = 'geeks'
length = 8
fillchar = '*'
  
print(string.rjust(length, fillchar))

输出:

***geeks