.center(width[, char]) 返回长度为 width 的字符串,字符串左右使用尽可能相同的 char 参数提供的字符填充。
不提供 char 参数则默认为空格
当 width 参数小于等于原字符串的长度时,原样返回
无法使左右字符数相等时候,字符串字符数为奇数时左侧字符会比右侧少 1,字符串字符数为偶数时左侧字符会比右侧多 1
>>> a = 'hello'
>>> a.center(20)
' hello '
>>> a.center(19, '-')
'-------hello-------'
>>> a.center(3)
'hello'
>>> a.center(8, '-')
'-hello--'
>>> b='runoob'
>>> b.center(9, '-')
'--runoob-'
>>>
Singee
Singee
ims***ee@gmail.com3年前 (2017-07-31)