python中的center

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

举个列子:

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

输出结果:

___hello___

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

猜你喜欢

转载自www.cnblogs.com/xwqhl/p/10675276.html