码迷,mamicode.com
首页 > 编程语言 > 详细

python center, ljust, rjust

时间:2016-04-16 20:56:23      阅读:147      评论:0      收藏:0      [点我收藏+]

标签:

例子

>>> 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 * *
*****

 

python center, ljust, rjust

标签:

原文地址:http://www.cnblogs.com/kaituorensheng/p/5399064.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!