python字符串处理rstrip()、lstrip()、strip()函数使用
来源:互联网 发布:手机在线网页源码 编辑:程序博客网 时间:2024/06/05 23:08
python字符串处理rstrip()、lstrip()、strip()函数使用
这三个函数都可传入一个参数,指定要去除的首尾字符,需要注意的是以字符数组的形式传参。
lstrip函数:去除字符串左边开始的指定字符,默认指定字符为空白字符(whiteSpace),如空格、回车\r,换行\n,制表符\t, 换页符\f;
rstrip函数:去除字符串右边结束的指定字符,默认指定字符为空白字符(whiteSpace),如空格、回车\r,换行\n,制表符\t, 换页符\f;
strip函数:去除字符串左右两边(首尾)的指定字符,默认指定字符为空白字符(whiteSpace),如空格、回车\r,换行\n,制表符\t, 换页符\f;
简单的使用实例:
# -*- coding: utf-8 -*-#默认空格sl=' abcdefeffe'print sl.lstrip()sl='aabbeaccccc'#去除开始的字符aprint sl.lstrip('a')#去除开始的字符a,bprint sl.lstrip ('ab')#去除开始的字符a,bprint sl.lstrip ('ba')#默认空格sr='abcdefeffe 'print sr.rstrip()sr='cccccaabba'#去除右边结束的字符aprint sr.rstrip('a')#去除右边结束的字符a,bprint sr.rstrip ('ab')#去除右边结束的字符a,bprint sr.rstrip ('ba')#默认空格s=' abcdefeffeababbaa 'print s.strip()s='abcdefeffeababbaa'print s.strip('a')print s.strip('ab')print s.strip('ba')
输出结果:
abcdefeffe
bbeaccccc
eaccccc
eaccccc
abcdefeffe
cccccaabb
ccccc
ccccc
abcdefeffeababbaa
bcdefeffeababb
cdefeffe
cdefeffe
阅读全文
0 0
- python字符串处理rstrip()、lstrip()、strip()函数使用
- Python strip lstrip rstrip使用方法(字符串处理空格)
- Python strip lstrip rstrip使用方法(字符串处理空格)
- Python strip lstrip rstrip使用方法(字符串处理空格)
- Python strip lstrip rstrip使用方法(字符串处理空格)
- python中strip\lstrip\rstrip的使用方法(字符串处理)
- strip,lstrip,rstrip Python
- python- strip lstrip rstrip
- Python-strip(),lstrip(),rstrip()
- python:strip()、rstrip()、lstrip()
- python-strip lstrip rstrip
- Python strip() lstrip() rstrip() 函数 去除空格
- Python strip() lstrip() rstrip() 函数 去除空格
- Python strip lstrip rstrip使用方
- Python strip lstrip rstrip使用方法
- python strip lstrip rstrip 用法
- Python strip lstrip rstrip使用方法
- Python strip lstrip rstrip使用方法
- z-index,标签之间的嵌套规则,精灵图,整站练习(css初始化)
- 僵尸进程
- 学习笔记之JavaScript——知识点(1)
- about the noise
- 解释器模式--注重的解释的思想
- python字符串处理rstrip()、lstrip()、strip()函数使用
- CSU-ACM2017暑假集训比赛1 C
- 如何获取指定objectName的QObject
- AngularJS 指令对象的Scope属性
- 刷题——分糖果
- 欢迎使用CSDN-markdown编辑器
- 深搜的剪枝
- 堆和栈的区别(转过无数次的文章)
- 剑指Offer——树的子结构