Description
The method strip() returns a copy of the string in which all chars have been stripped from the beginning and the end of the string (default whitespace characters).
Syntax
Following is the syntax for strip() method
str.strip([chars]);
Parameters
-
chars -- The characters to be removed from beginning or end of the string.
Return Value
This method returns a copy of the string in which all chars have been stripped from the beginning and the end of the string.
Example
The following example shows the usage of strip() method.
#!/usr/bin/python str = "0000000this is string example....wow!!!0000000"; print str.strip( '0' );
Let us compile and run the above program, this will produce the following result:
this is string example....wow!!! reference: http://www.tutorialspoint.com/python/string_strip.htm
本文详细介绍了 Python 中的字符串处理方法 strip() 的使用方法。该方法用于移除字符串两端的指定字符,默认情况下移除空白字符。文章通过示例展示了如何使用 strip() 方法,并解释了其参数的作用。
896

被折叠的 条评论
为什么被折叠?



