Python字符串方法详细介绍2_删除
来源:互联网 发布:ubuntu系统软件不见了 编辑:程序博客网 时间:2024/06/15 16:59
# 2.删减strip([chars]),lstrip([chars]),rstrip([chars])(1)strip([chars]) strip()函数族用以去除字符串两端的空白符,保留中间的空白符空白符由string.whitespace常量定义>>> print ' abc d '.strip().replace(' ','*')abc*dx = ''' line one line twoand line three'''>>> print x.replace(' ','*')***line*one****line*twoand*line*three****>>> print x.strip().replace(' ','*')line*one****line*twoand*line*three当strip()方法指定输入参数时,删除指定的字符,如:>>> print 'abc'.strip('a')bc(2)lstrip([chars])和rstrip([chars])分别删除字符串左端和右端的空白符或指定字符。这两个方法只会作用于对应端的指定字符(默认作用于空白符)而对应端不管有多少指定字符都会被删除>>> print ' abc'.lstrip().replace(' ','*')abc>>> print 'abc '.lstrip().replace(' ','*')abc***>>> print 'aabac'.lstrip('a')bac>>> print 'abc'.lstrip('c')abc>>> print ' abc'.lstrip().replace(' ','*')abc>>> print ' abc'.rstrip().replace(' ','*')***abc>>> print 'abc'.rstrip('a')abcprint 'abc'.rstrip('c')>>> print 'abc'.rstrip('c')ab
0 0
- Python字符串方法详细介绍2_删除
- Python字符串方法详细介绍1_填充
- Python字符串方法详细介绍3_变形
- Python字符串基本方法介绍
- Python学习_我该如何删除字符串中的空白
- python 删除 ._文件
- Python学习笔记_字符串类型内建方法
- Python的详细介绍
- python socket 详细介绍
- Python----matplotlib详细介绍
- Python 删除字符串
- python删除字符串
- Math方法详细介绍
- $.each()方法详细介绍
- struts2_通配符_动态方法_详细
- python 字符串介绍
- [mobi文件格式详细介绍一]_[资料篇]
- OpenGL函数_ gl.glenable()详细介绍
- startActivityForResult和setResult详解
- Android开发:setAlpha()方法和常用RGB颜色表----颜色, r g b分量数值(int), 16进制表示 一一对应
- C++刷题九
- Python特殊语法:filter、map、reduce、lambda [转]
- 数据结构:静态查找表(线性链表)
- Python字符串方法详细介绍2_删除
- Codeforces Round 445 C. DZY Loves Physics
- view 属性
- QT多文档程序中显示背景图片
- 数据结构:二叉排序树
- 二分查找法—do-while实现
- 对象所有权
- 边做游戏边学android—前言
- Html5学习-JQuery mobile--button学习使用