python strip() 函数探究
strip()方法语法:str.strip([chars]);
声明:str为字符串,rm为要删除的字符序列
- str.strip(rm) 删除字符串中
开头、结尾处,位于rm删除序列的字符
eg1:
#首尾端'0'被删除,中间不动
>>> t='0000this is string example0000wow!!!0000'
>>> t.strip('0')
'this is string example0000wow!!!'
eg2:
#无入参,默认删除首尾所有空字符 ‘\n\t空格‘
>>>s='\n 0000this is string example0000wow!!!0000\n \t'
>>> s.strip()
'0000this is string example0000wow!!!0000'
- str.lstrip(rm) 删除字符串中
开头处,位于 rm删除序列的字符
t='0000this is string example0000wow!!!0000'
>>> t.lstrip('0')
'this is string example0000wow!!!0000'
#空入参同样可删除首部空字符,'.rstrip()'同理
s='\n 0000this is string example0000wow!!!0000\n \t'
>>> s.lstrip()
'0000this is string example0000wow!!!0000\n \t'
- str.rstrip(rm) 删除字符串中
结尾处,位于 rm删除序列的字符
t='0000this is string example0000wow!!!0000'
>>> t.rstrip('0')
'0000this is string example0000wow!!!'
s='\n 0000this is string example0000wow!!!0000\n \t'
>>> s.rstrip()
'\n 0000this is string example0000wow!!!0000'
究竟何为'首尾'?实验之
s='\n 0000this is string is example0000wow!!!0000\n \t'
>>> s.lstrip('\n 0')
'this is string is example0000wow!!!0000\n \t'
#首部'\n 0000'被删除
>>> s.lstrip('\n 0this')
'ring is example0000wow!!!0000\n \t'
#奇妙啊,我的目标是删除首部'\n 0000this',结果'\n 0000this is st'全被删除,说明:符合入参('\n 0this')的字符皆是删除对象,不论字符顺序
#但,为何string后面的is没有删除?因为,'首部'指的是'连续符合'入参要求的字符,string中的'r'隔断了入参的连续字符要求,python判定首部结束。
实验证明:所谓的首、尾,判定依据是-是否连续符合入参要求,如果符合,不论顺序,皆可操作,一直到遇到第一个非入参字符为止.
python strip() 函数探究的更多相关文章
- python strip()函数 介绍
python strip()函数 介绍,需要的朋友可以参考一下 函数原型 声明:s为字符串,rm为要删除的字符序列 s.strip(rm) 删除s字符串中开头.结尾处,位于 rm删除 ...
- python strip()函数
转发:jihite-博客园-python strip()函数 函数原型 声明:s为字符串,rm为要删除的字符序列 s.strip(rm) 删除s字符串中开头.结尾处,位于 rm删除序列的 ...
- python3.4学习笔记(二十) python strip()函数 去空格\n\r\t函数的用法
python3.4学习笔记(二十) python strip()函数 去空格\n\r\t函数的用法 在Python中字符串处理函数里有三个去空格(包括'\n', '\r', '\t', ' ')的函数 ...
- python strip() 函数和 split() 函数的详解及实例
strip是删除的意思:split则是分割的意思.strip可以删除字符串的某些字符,split则是根据规定的字符将字符串进行分割. 1.Python strip()函数 介绍 函数原型 声明:s为字 ...
- (转)python strip()函数 去空格\n\r\t函数的用法
原文:http://www.cnblogs.com/zdz8207/p/python_learn_note_20.html python3.4学习笔记(二十) python strip()函数 去空格 ...
- python strip()函数和Split函数的用法总结
strip函数原型 声明:s为字符串,rm为要删除的字符序列. 只能删除开头或是结尾的字符或是字符串.不能删除中间的字符或是字符串. s.strip(rm) 删除s字符串中开头.结尾处,位于 rm删除 ...
- python Strip函数和Split函数的用法总结 (python2.0,但用法与3.0是差不多的)
strip函数原型 声明:s为字符串,rm为要删除的字符序列. 只能删除开头或是结尾的字符或是字符串.不能删除中间的字符或是字符串. s.strip(rm) 删除s字符串中开头.结尾处, ...
- python strip()函数 os.popen()
函数原型 声明:s为字符串,rm为要删除的字符序列 s.strip(rm) 删除s字符串中开头.结尾处,位于 rm删除序列的字符 s.lstrip(rm) 删除s字符串中开头处,位于 rm删除序列的字 ...
- Python strip()函数用法
Python中字符串处理函数里有三个去空格(包括'\n', '\r', '\t', ' ')的函数: strip 同时去掉左右两边的空格lstrip 去掉左边的空格rstrip 去掉右边的空格 具体示 ...
随机推荐
- MFC项目实战(1)文件管理器--界面设计篇
1.创建项目 文件管理器是一个基于对话框的应用程序.首先新建一个“MFC应用程序”类型的项目,然后输入新建项目的名称“FileMng”,并指定该项目保存的位置,单击“确定”按钮,如图所示. 在弹出的“ ...
- DataTabless Add rows
参考官网案例:https://datatables.net/examples/api/add_row.html JS: $(document).ready(function() { var t ...
- 浅谈UML学习笔记之用例图
最近一直在学习UML的基础知识,再看完视频之后,并没有很好的总结,在画图的过程中发现了很多的问题,下面是看书的过程自己总结的UML用例图的一点知识,与大家分享一下. 一.概念 用例图是由参与者.用例以 ...
- bzoj1486【HNOI2009】最小圈
1486: [HNOI2009]最小圈 Time Limit: 10 Sec Memory Limit: 64 MB Submit: 1778 Solved: 827 [Submit][Statu ...
- beego07----web博客
conf/app.conf appname = blog1 httpport = 8080 runmode = dev name=admin pwd=admin controllersmy/attac ...
- OSD锁定怎么解锁?
方法是这样的: 先按中间的建关掉显示器电源,关了显示器后按住左键,在按中间的建开机,这时屏幕闪一下就解锁了.在按中间的建打开显示器就行了. 加锁的方法和解锁一样
- ssh远程连接docker中linux(ubuntu/centos)
ssh远程连接docker中linux(ubuntu/centos) https://www.jianshu.com/p/9e4d50ddc57e centos docker pull centos: ...
- Linux 系统管理命令 - free - 查看系统内存信息
命令详解 重要星级: ★★★★★ 功能说明: free 命令用于显示系统内存状态,具体包括系统物理内存.虚拟内存.共享内存和系统缓存等. 语法格式: free [option] free [选项] 说 ...
- bzoj 4195: [Noi2015]程序自动分析【并查集】
等于有传递性,所以hash一下把等于用并查集连起来,然后再判断不等于是否合法即可 #include<iostream> #include<cstdio> #include< ...
- bzoj P2045 方格取数加强版【最大费用最大流】
今天脑子不太清醒,把数据范围看小了一直TTTTLE-- 最大费用最大流,每个格子拆成两个(x,y),(x,y)',(x,y)向(x,y)'连一条费用a[x][y]流量1的边表示选的一次,再连一条费用0 ...