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 |
2 >>> print '|', x.lstrip(), '|', x.rstrip(), '|', x.strip(), '|'
3 | hej | hej | hej |
4 >>> x = 'xyxxyy hejyx yyx'
5 >>> print '|'+x.strip('xy')+'|'
6 | hejyx |