在python API中这样解释strip()函数:

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAA+EAAABmCAIAAAArhgdMAAATe0lEQVR4nO2d0bHbOhJEGZQzcjwOx8m8GPZjqzYA7se19SgCaPQMQRLUPadcLokAZhoDEGzLsu+yAgAAAADATCx3CwAAAAAAgDfw6AAAAAAAc4FHBwAAAACYCzw6AAAAAMBc4NEBAAAAAOYCjw4AAAAAMBd4dAAAAACAucCjAwAAAADMBR4dAAAAAGAu8OgPYNlwt5Y+z1ILAAAAMCG4qNvwLexDzW4p+6ETAQAAALgYPNM9hNzqQ61tVfZD5wIAAABwJRimDP/8+rEsy7L8+PVPZnjUpz7U17ZkP3Q6AAAAAJeBW8qAR3fAowMAAADk+I5u6ffPZVl+/r4pe8KhnmdqT7XLIjg2HQAAAEBwkVWa6X/5+PoQHI9+ulHGowMAAADkyFul6L96nMSW/f2aCh4djw4AAAAwKRd59Kv468A3vL4z/vvnvml5c+ub9p+/3yJtvnb+lmD3dfS/AX7+fk/13k071y3OEAcdttUkRm2vtLp1Z3pkRgAAAACfTccqOQZud3Ft27gysm6tNrX545//eu7GJ+a7XtUgP378WJblx69//pjtovNXkPKfjP5r4f8MKUW0piMM7hFH2wpbXdZWut0oR7OWjUcHAAAAECirpG1i1WbtrLnu73jEiJkrjXPtX4c6Hr3qv3WqZvD9JdOjm02aUEyns+/Co9kBAAAA4EXSY7Vaj5jCwx59ffu+SstkWx69958qBjz6H02vvrpE1b83uN6jLwViVFVzNDsAAAAAvHC/61JtMi+2msSHsiKvxb/fOSl89MQe/dUh9HG1iOM3bV2482encnjug3kAAAAAKHGtkunAhn+OHuDrm+RvtvnLHr/b8Xcb/c+vH7Wvpgz06PuvtDt1u9ejm01dkXh0AAAAgBzjv4/uRKteaX3XYnexrbf4B551J735XLvyX6UP8ejFPxnt/dcuiVKL66/WVvVCRtzx6KHNgEEHAAAA0PRNnnDGOwPX6l9tEm9bXtD06O/UvtOy7five64MV/9xS7XX5n+FERLKWehSi/q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AAPdyjzVZ3qm2rgc8utkkcrXSaeWtpN230VKEgmxbq6HKgOY0deoyyE5AtA5af1eMnq+eIwAAAMCVfJo16TozAAAAAIDJ+UAL638ADAAAAAAwIbhYAAAAAIC5wKMDAAAAAMwFHh0AAAAAYC7w6AAAAAAAc4FHBwAAAACYCzw6AAAAAMBc/B+l8YxApY2jugAAAABJRU5ErkJggg==" alt="" />

声明:s为字符串,rm为要删除的字符序列

s.strip(rm)        删除s字符串中开头、结尾处,位于 rm删除序列的字符

s.lstrip(rm)       删除s字符串中开头处,位于 rm删除序列的字符

s.rstrip(rm)      删除s字符串中结尾处,位于 rm删除序列的字符

注意:

1. 当rm为空时,默认删除空白符(包括'\n', '\r',  '\t',  ' ')

例如:

>>> a='   Hello World   '
>>> a
' Hello World '
>>> a.strip()
'Hello World' >>> x='\t\r\npython'
>>> x
'\t\r\npython'
>>> x.strip()
'python'

2.rm删除序列是只要边(开头或结尾)上的字符在删除序列内,就删除掉。

例如:

>>> aString='123love'
>>> aString
'123love'
>>> aString.strip('')
'3love'

Python中strip()函数的更多相关文章

  1. python中strip函数的用法

    python中往往使用剥除函数strip()来对用户的输入进行清理.strip函数的最一般形式为: str.strip('序列') 其中,序列是一段字符串,该函数表示从头或者从尾部开始进行扫描,如果扫 ...

  2. python中strip()函数的理解

    1.strip()函数 函数原型 声明:s为字符串.rm为要删除的字符序列 s.strip(rm) :删除s字符串中开头.结尾处.位于 rm删除序列的字符 s.lstrip(rm) :删除s字符串中开 ...

  3. python中Strip()函数的用法

    Python strip() 方法用于移除字符串头尾指定的字符(默认为空格或换行符)或字符序列. 注意:该方法只能删除开头或是结尾的字符,不能删除中间部分的字符. str.strip([chars]) ...

  4. Python中strip()、lstrip()、rstrip()函数的用法

    Python中使用函数strip().lstrip().rstrip()来剔除字符串前后的特定字符 函数语法为:str.strip(chars) 返回值是一个新的字符串,不更改源字符串 其中,参数ch ...

  5. Python中split()函数的用法及实际使用示例

    Python中split()函数,通常用于将字符串切片并转换为列表. 一.函数说明: split():语法:str.split(str="",num=string.count(st ...

  6. Python中readline()函数 去除换行符

    从Python中readline()函数读取的一行内容中含有换行符\n,很多时候我们需要处理不含有换行符的字符串,此时就要去掉换行符\n. 方法是使用strip()函数. 例子如下: f = open ...

  7. python中filter函数

    python中filter()函数   filter()函数是 Python 内置的另一个有用的高阶函数,filter()函数接收一个函数 f 和一个list,这个函数 f 的作用是对每个元素进行判断 ...

  8. Python中strip方法的妙用

    [开胃小菜] 当提到python中strip方法,想必凡接触过python的同行都知道它主要用来切除空格.有下面两种方法来实现. 方法一:用内置函数 #<python> if __name ...

  9. python中strip,lstrip,rstrip简介

    一.起因 今天在做角色控制中,有一个地方用到rstrip,判断用户请求的url是否与数据库对应可用权限中url相符. if request.path == x.url or request.path. ...

随机推荐

  1. 如何安装php?

    1.解压apache文件 2.进行注册,写地址,邮箱 3.下一步选择Typical 4.下一步随意选个安装路径 5.解压php文件 6.把php.ini-development文件改为php.ini ...

  2. 关于EOF的种种。

    EOF读取数据是读取一个向下进行一次,知道没有数据可以读取. EOF的使用,用while和eof的

  3. BZOJ 1042 硬币购物

    先不考虑限制,那么有dp[i]表示i元钱的方案数. 然后考虑限制,发现可以容斥. 其实整个题就是两个容斥原理.感觉出的蛮好的. #include<iostream> #include< ...

  4. BZOJ 3163 Eden的新背包问题

    分治背包+单调队列优化. 但是为什么maxn要1w多?...不怎么懂. #include<iostream> #include<cstdio> #include<cstr ...

  5. BZOJ 1486 最小圈

    二分答案是显然的,我们需要dfs版spfa判一下负环. 看起来是n^2其实很快. #include<iostream> #include<cstdio> #include< ...

  6. Math中floor,round和ceil的区别

    floor 返回不大于的最大整数 round 则是4舍5入的计算,入的时候是到大于它的整数(当-1.5时可见,四舍五入后得到的结果不是我们期待的,解决办法是先对他取绝对值,然后在用round方法) r ...

  7. cJSON_hacking

    /****************************************************************************** * cJSON_hacking * * ...

  8. OpenFlow Switch学习笔记(三)——Flow Tables

    这次我们主要讨论下OpenFlow Switch的核心组件之一——Flow Tables,以了解其内部的 matching 以及 action handling 机制.下文将会分为几个部分来逐步详述O ...

  9. PAT (Basic Level) Practise:1027. 打印沙漏

    [题目链接] 本题要求你写个程序把给定的符号打印成沙漏的形状.例如给定17个“*”,要求按下列格式打印 ***** *** * *** ***** 所谓“沙漏形状”,是指每行输出奇数个符号:各行符号中 ...

  10. eclipse关联源码 Failed to create the part's controls

    在eclipse中关联源码时: 1.出现Failed to create the part's controls错误, 2.而attach source 这个按钮却没有出现. 问题原由:eclipse ...