Python中字符串对齐方法介绍
2018-10-12 13:53
686 查看
目的
实现字符串的左对齐,右对齐,居中对齐。
方法
字符串内置了以下方法:其中width是指包含字符串S在内的宽度,fillchar默认是空格,也可以指定填充字符
string.ljust(s, width[, fillchar])
string.rjust(s, width[, fillchar])
string.center(s, width[, fillchar])
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!++
您可能感兴趣的文章:
相关文章推荐
- Python中字符串对齐方法介绍
- Python字符串拼接六种方法介绍
- Python中几种操作字符串的方法的介绍
- Python字符串基本方法介绍
- Python字符串拼接六种方法介绍
- 在Python中用split()方法分割字符串的使用介绍
- 在Python中用split()方法分割字符串的使用介绍
- Python字符串方法详细介绍3_变形
- Python字符串方法详细介绍1_填充
- Python 字符串方法详解
- python通过zlib实现压缩与解压字符串的方法
- Windows和Linux下使用Python访问SqlServer的方法介绍
- python 学习之字符串方法
- python判断给定的字符串是否是有效日期的方法
- python清除字符串中间空格的方法
- python中字符串常用的方法解析
- python去掉字符串中重复字符的方法
- python字符串方法
- token的介绍和用python 生成token的几种方法
- python字符串常用的方法解析