描述
这个rjust()方法返回在长度宽度的字符串中右对齐的字符串。填充是使用指定的填充字符(默认为空格)完成的。如果宽度小于 len(s),则返回原始字符串。
用法
以下是语法rjust()方法 -
str.rjust(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!!!
相关用法
- Python 3 String rstrip()用法及代码示例
- Python 3 String replace()用法及代码示例
- Python 3 String rindex()用法及代码示例
- Python 3 String rfind()用法及代码示例
- Python 3 String isupper()用法及代码示例
- Python 3 String decode()用法及代码示例
- Python 3 String maketrans()用法及代码示例
- Python 3 String find()用法及代码示例
- Python 3 String isspace()用法及代码示例
- Python 3 String upper()用法及代码示例
- Python 3 String expandtabs()用法及代码示例
- Python 3 String lower()用法及代码示例
- Python 3 String zfill()用法及代码示例
- Python 3 String index()用法及代码示例
- Python 3 String split()用法及代码示例
- Python 3 String strip()用法及代码示例
- Python 3 String startswith()用法及代码示例
- Python 3 String isalnum()用法及代码示例
- Python 3 String encode()用法及代码示例
- Python 3 String join()用法及代码示例
注:本文由纯净天空筛选整理自 Python 3 - String rjust() Method。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。