1 # -*- coding: utf-8 -*- 2 """ 3 去除字符串两端的空格和字符 4 lstrip()、rstrip()、strip() 5 返回字符串的拷贝 6 """ 7 x = ‘ aaa ‘ 8 9 print ‘|‘,x.lstrip(),‘|‘,x.rstrip(),‘|‘,x.strip(),‘|‘ 10 # Output: | aaa | aaa | aaa | 11 12 x = ‘xyxxyy hejyx yyx‘ 13 print ‘|‘+ x.strip(‘xy‘)+‘|‘ 14 # Output:| hejyx | 15 16 x = ‘yxyxyxyxyxyx yyxyxyxyx‘ 17 print x.lstrip(‘xy‘) 18 # Output: yyxyxyxyx 19 20 print x.rstrip(‘xy‘) 21 # Output: yxyxyxyxyxyx 22 23 x = ‘xyyyyyxyxyxyxx‘ 24 print x.lstrip(‘xy‘) 25 # Output:为空 26 27 print x.rstrip(‘xy‘) 28 # Output:为空
原文地址:http://www.cnblogs.com/tmmuyb/p/3794634.html