python中调整字符串宽度并制定填充字符、内置center方法

>>> a = "good"  ##测试字符串
>>> a
'good'
>>> type(a)
<class 'str'>
>>> a.center(1)   ## 指定宽度1
'good'
>>> a.center(10)  ## 指定宽度10,默认使用空格填充
'   good   '
>>> a.center(10,"x")  ## 指定宽度10,并指定使用x填充
'xxxgoodxxx'
>>> a.center(20,"1")  ## 指定宽度20,并制定使用1填充
'11111111good11111111'
原文地址:https://www.cnblogs.com/liujiaxin2018/p/14445050.html