python中的center

it2026-05-11  5

python中的center

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

举个列子:

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

输出结果:

___hello___

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

posted on 2019-04-09 10:18 恒笛 阅读( ...) 评论( ...) 编辑 收藏

转载于:https://www.cnblogs.com/xwqhl/p/10675276.html

最新回复(0)