[Python] String strip() Method

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).

在string中删掉strip(char)的所有char字符。

Syntax

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

str = ‘1111234    adad‘;
print str.strip(‘1‘);

  

Result: 234    adad

  

时间: 2024-10-29 03:24:00

[Python] String strip() Method的相关文章

Python String startswith() Method

一,摘自官方API  https://docs.python.org/3/library/stdtypes.html#methods str.startswith(prefix[, start[, end]]) Return True if string starts with the prefix, otherwise return False. prefix can also be a tuple of prefixes to look for. With optional start, t

python的string.strip(s[, chars])方法的各种小细节

下面的英文说明是官方给出: string.strip(s[, chars]) Return a copy of the string with leading and trailing characters removed. If chars is omitted or None, whitespace characters are removed. If given and not None, chars must be a string; the characters in the stri

Python str.strip()函数

下面的英文说明是官方给出: string.strip(s[, chars]) Return a copy of the string with leadingand trailing characters removed. If chars is omitted orNone, whitespace characters are removed. If given and not None, chars must be astring; the characters in the string

Python string objects implementation

http://www.laurentluce.com/posts/python-string-objects-implementation/ Python string objects implementation June 19, 2011 This article describes how string objects are managed by Python internally and how string search is done. PyStringObject structu

Python中strip方法的妙用

[开胃小菜] 当提到python中strip方法,想必凡接触过python的同行都知道它主要用来切除空格.有以下两种方法来实现. 方法一:用内置函数 #<python> if __name__ == '__main__': str = ' Hello world ' print '[%s]' %str.strip() #</python> 方法二:调用string模块中方法 #<python> import string if __name__ == '__main__

跟黄哥学python序列文章之python方法链(method chaining)

# 跟黄哥学python序列文章之python方法链(method chaining) ## 写这篇文章来由,有朋友说下面这样的代码看不懂. choice = raw_input("please input:\n").strip()[0].lower() 很多对于有经验的程序员来说,这些都不是事, 但对于初学者来说,看到这样的语法头有点大. ## 这个其实是面向对象中方法链的概念. ## 请看维基百科上Method chaining的定义 Method chaining, also k

python string

string比较连接 >>> s1="python string" >>> len(s) 13 >>> s2=" python string2 " >>> s=s1+s2 >>> s 'python string python string2 ' >>> >>> cmp(s1,s2) 1 string 截取 >>> s1[0

python中strip()方法学习笔记

Python strip() 方法用于移除字符串头尾指定的字符(默认为空格). 当使用strip('xxx'),只要字符串头尾有"xxx"中的一个,就会去掉,而不是符合字符串''xxx''才去掉 1 >>> string = 'aaabbbccc' 2 >>> string.strip('abc') 3 '' 4 >>> string2 = 'aaaffbbcc' 5 >>> string2.strip('abc'

Python中strip()、lstrip()、rstrip()用法详解

Python中有三个去除头尾字符.空白符的函数,它们依次为: strip: 用来去除头尾字符.空白符(包括\n.\r.\t.' ',即:换行.回车.制表符.空格)lstrip:用来去除开头字符.空白符(包括\n.\r.\t.' ',即:换行.回车.制表符.空格)rstrip:用来去除结尾字符.空白符(包括\n.\r.\t.' ',即:换行.回车.制表符.空格) 注意:这些函数都只会删除头和尾的字符,中间的不会删除. 用法分别为:string.strip([chars])string.lstrip