Py&禅

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

Solution:
使用lstrip, rstrip, strip方法。
>>> x = '    hej   '
>>> print '|', x.lstrip( ), '|', x.rstrip( ), '|', x.strip( ), '|'
| hej    |     hej | hej |

Discussion:
也可以指定要去除的元素,而不单单限于空白
>>>x = 'xyxxyy hejyx yyx'
>>>print '|'+x.strip('xy')+'|'
| hejyx |

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