Py&禅

博客园 首页 新随笔 联系 订阅 管理
Problem:

Solution:
使用ljust(), rjust(), center(),来调整字符串对象的位置
>>> print '|', 'hej'.ljust(20), '|', 'hej'.rjust(20), '|', 'hej'.center(20), '|'
| hej             |             hej |       hej       |

使用ljust, rjust, center內建函数的第二个叁数来对空白位置填充
>>> print 'hej'.center(20, '+')
++++++++hej+++++++++

posted on 2010-05-30 10:08  Py&禅  阅读(90)  评论(0)    收藏  举报