Ray's playground

 

Recipe 1.5. Trimming Space from the Ends of a String(Python Cookbook)

1 >>> x = '     hej    '
2 >>> print '|', x.lstrip(), '|', x.rstrip(), '|', x.strip(), '|'
3 | hej     |      hej | hej |
4 >>> x = 'xyxxyy hejyx yyx'
5 >>> print '|'+x.strip('xy')+'|'
6 | hejyx |

 

posted on 2010-12-18 23:05  Ray Z  阅读(125)  评论(0编辑  收藏  举报

导航