[Python笔记]Strip

Python中:

str.strip(): 用来去除头尾字符、空白符(包括\n、\r、\t、' ')

str.lstrip():同strip(), 但是只去除头部字符

str.rstrip():同strip(), 但是只去除尾部字符

但是我们发现,中间的没有处理!

其实我们可以使用str.replace(old, new)函数:

str.replace(old, new)

或是直接删除:

str.replace(old, "")

posted @ 2021-09-04 18:19  linux_farmer  阅读(69)  评论(0编辑  收藏  举报