您的位置:首页 > 编程语言 > Python开发

python center, ljust, rjust

2016-04-16 18:37 501 查看

例子

>>> 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 * '*'
'*****
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: