12:center
语法:str.center(width,[fillchar])
解释:返回一个长度为width,两边用fillchar填充的字符串,默认为空格填充;若width小于len(str),则返回原字符串。
>>> x = 'apple'
>>> x.center(9)
' apple '
>>> x.center(9,'*')
'**apple**'
>>> x.center(3)
'apple'
13.ljust
语法:str.ljust(width,[fillchar])
解释:返回一个长度为width,开头是当前字符串的副本,末尾使用fillchar填充,默认为空格,若width小于len(str),则返回原字符串。
>>> x = 'apple'
>>> x.ljust(6)
'apple '
>>> x.ljust(6,'*')
'apple*'
>>> x.ljust(4)
'apple'
14.rjust
语法:str.rjust(width,[fillchar])
解释:返回一个长度为width,末尾是当前字符串的副本,开头使用fillchar填充,默认为空格,若width小于len(str),则返回原字符串。