python center, ljust, rjust

例子

>>> s = "jihite"

>>> s.center(10, "*")
'**jihite**'

>>> s.ljust(10, "*")
'jihite****'

>>> s.rjust(10, "*")
'****jihite'

说明

center,ljust,rjust分别把字符串放在10个*的中央、靠左、靠右。注:字符窜要替换*的位置,如果超过*的个数,直接就没有*了,例如:

>>> s
'jihite'
>>> s.center(3, '*')
'jihite'

*

>>> 5 * '*'
'*****

 

posted @ 2016-04-16 18:37  jihite  阅读(1255)  评论(0编辑  收藏  举报