码迷,mamicode.com
首页 > 编程语言 > 详细

python-->基础-->003->字符串处理

时间:2016-10-22 12:08:44      阅读:131      评论:0      收藏:0      [点我收藏+]

标签:字符串处理   print   rip   tail   strong   空格   int   blog   for   

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

说明:即为去除字符串的首尾(即头部和尾部)的白空格(空格本身,回车\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

python-->基础-->003->字符串处理

标签:字符串处理   print   rip   tail   strong   空格   int   blog   for   

原文地址:http://www.cnblogs.com/mangguoxiansheng/p/5987088.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!