Python strip() 方法

原文地址: https://blog.csdn.net/xc_zhou/article/details/80810010

描述

Python strip() 方法用于移除字符串头尾指定的字符(默认为空格)。

语法

strip()方法语法:
在这里插入图片描述
参数

chars – 移除字符串头尾指定的字符。

返回值

返回移除字符串头尾指定的字符生成的新字符串。

实例

以下实例展示了strip()函数的使用方法:

1.移除字符串头尾指定的字符(此处移除的是“0”)
在这里插入图片描述
2.只移除字符串头尾指定的字符,中间部分不会移除
在这里插入图片描述
输出结果中间部分的 0 还是存在的

更多字符串操作方法:
Python中strip()、lstrip()、rstrip()用法详解
见链接:https://www.cnblogs.com/huangbiquan/p/7923008.html

猜你喜欢

转载自blog.csdn.net/Arno_Pei/article/details/87915393