Python rjust()方法
描述
Python rjust() 返回一個原字符串右對齊,並使用空格填充至長度width 的新字符串。 如果指定的長度小於字符串的長度則返回原字符串。
語法
rjust()方法語法:
str.rjust(width[, fillchar])
參數
- width -- 指定填充指定字符後中字符串的總長度.
- fillchar -- 填充的字符,默認為空格。
返回值
返回一個原字符串右對齊,並使用空格填充至長度width 的新字符串。 如果指定的長度小於字符串的長度則返回原字符串
實例
以下實例展示了rjust()函數的使用方法:
#!/usr/bin/python str = "this is string example....wow!!!"; print str.rjust(50, '0');
以上實例輸出結果如下:
000000000000000000this is string example....wow!!!