一、去除字符串首尾白空格

说明:即为去除字符串的首尾(即头部和尾部)的白空格(空格本身,回车\r,换行\n,制表符\t, 换页符\f )

实例:

str01 = ' abc def # '

print str01
print str01.strip()  #删除了字符串的首尾的百空格
print str01.lstrip() 》#删除左边的百空格
print str01.rstrip()  #删除右边的百空格

 abc def #   -->左空格和右空格都在
abc def #    -->左右两边的空格都被删除了
abc def #    -->删除了左空格
 abc def #   -->删除了右空格

strip一般用来是去除一个字符的首尾的多余的,不可见的字符(所谓的白空格).

 

 

 

 

http://blog.csdn.net/forevernull/article/details/22529705

posted on 2016-10-22 11:13  mangguo  阅读(198)  评论(0编辑  收藏  举报