当前位置: 首页 > 文档资料 > Python 中文教程 >

strip([chars])

优质
小牛编辑
133浏览
2023-12-01

描述 (Description)

方法strip()返回字符串的副本,其中所有字符都已从字符串的开头和结尾处删除(默认的空白字符)。

语法 (Syntax)

以下是strip()方法的语法 -

str.strip([chars]);

参数 (Parameters)

  • chars - 要从字符串的开头或结尾删除的字符。

返回值 (Return Value)

此方法返回字符串的副本,其中所有字符都已从字符串的开头和结尾处删除。

例子 (Example)

以下示例显示了strip()方法的用法。

#!/usr/bin/python
str = "0000000this is string example....wow!!!0000000";
print str.strip( '0' )

当我们运行上面的程序时,它产生以下结果 -

this is string example....wow!!!