python去除空格和换行符的方法

Python78

python去除空格和换行符的方法

原创

RoyFans©著作权

文章标签 编程 文章分类 Python 编程语言

©著作权归作者所有:来自51CTO博客作者RoyFans的原创作品,请联系作者获取转载授权,否则将追究法律责任

一、去除空格

strip()"   xyz   ".strip()            # returns "xyz"  "   xyz   ".lstrip()           # returns "xyz   "  "   xyz   ".rstrip()           # returns "   xyz"  "  x y z  ".replace(' ', '')   # returns "xyz"

二、替换 replace("space","")

用replace("\n", ""),后边的串替换掉前边的

  • 收藏
  • 评论
  • *举报

上一篇:python 中 for使用小技巧

下一篇:python爬虫--爬取cctv连续剧

Original: https://blog.51cto.com/u_15762555/5612619
Author: RoyFans
Title: python去除空格和换行符的方法