目的
实现字符串的左对齐,右对齐,居中对齐。
方法
字符串内置了以下方法:其中width是指包含字符串S在内的宽度,fillchar默认是空格,也可以指定填充字符
In [7]: print a.ljust(10,'+')
Hello!++++
In [8]: print a.rjust(10,'+')
++++Hello!
In [9]: print a.center(10,'+')
++Hello!++
python怎么学习?python怎么入门?python在哪学?python怎么学才快?不用担心,这里为大家提供了python速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号