junjie 通过本文主要向大家介绍了python中字符串的方法,python字符串方法,python字符串处理,python 字符串,python 字符串转数字等相关知识,希望对您有所帮助,也希望大家支持linkedu.com www.linkedu.com
目的
实现字符串的左对齐,右对齐,居中对齐。
方法
字符串内置了以下方法:其中width是指包含字符串S在内的宽度,fillchar默认是空格,也可以指定填充字符
string.ljust(s, width[, fillchar])
string.rjust(s, width[, fillchar])
string.center(s, width[, fillchar])
</div>
In [6]: a='Hello!'
In [7]: print a.ljust(10,'+')
Hello!++++
In [8]: print a.rjust(10,'+')
++++Hello!
In [9]: print a.center(10,'+')
++Hello!++
</div>

