这篇文章主要介绍了Python中字符串对齐方法介绍,本文介绍Python字符串内置方法ljust、rjust、center的用法,需要的朋友可以参考下 目的 实现字符串的左对齐,右对齐,居中对齐。 方法 字符串内置了以下方法:其中width是指包含字符串S在内的宽度,fillchar默认是空格,也可以指定填充字符
In [7]: print a.ljust(10,'+') In [8]: print a.rjust(10,'+') In [9]: print a.center(10,'+') |