python中的center

center(self,width,fillchar=None)让字符串居中显示,width定义字长度,fillchar定义空白处填充,不填写默认为空白

举个列子:

1 a = "hello"
2 a1 = a.center(11 , "_")
3 print(a1)

输出结果:

___hello___

我们定义总长度为11,空白处用“_”下划线填充

posted @ 2017-09-14 09:46  萌萌哒小强儿  阅读(1010)  评论(0编辑  收藏  举报