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