Python中的split()
来源:互联网 发布:java 切换虚拟机模式 编辑:程序博客网 时间:2024/06/05 03:33
split():分割字符串,分割符号为函数输入参数。默认分隔符号为空格。
strip():
Python中的strip用于去除字符串的首尾字符,同理,lstrip用于去除左边的字符,rstrip用于去除右边的字符。
这三个函数都可传入一个参数,指定要去除的首尾字符。
需要注意的是,传入的是一个字符数组,编译器去除两端所有相应的字符,直到没有匹配的字符,比如:
theString
=
'saaaay yes no yaaaass'
print
theString.strip(
'say'
)
theString依次被去除首尾在['s','a','y']数组内的字符,直到字符在不数组内。所以,输出的结果为:
yes no
比较简单吧,lstrip和rstrip原理是一样的。
注意:当没有传入参数时,是默认去除首尾空格的。
theString
=
'saaaay yes no yaaaass'
print
theString.strip(
'say'
)
print
theString.strip(
'say '
)
#say后面有空格
print
theString.lstrip(
'say'
)
print
theString.rstrip(
'say'
)
运行结果:
yes no
es no
yes no yaaaass
saaaay yes no
- Python中的split()
- Python中的split方法
- python中的split函数
- Python中的split()函数
- Python中的join和split
- python 中的split()和strip()
- python中的strip和split
- Python 中的join()与split()
- Python 中的join()与split()
- python中的join和split
- Python 中的 split()函数
- python 中的split()函数和os.path.split()函数
- python 中的split()函数和os.path.split()函数
- MFC实现python中的split功能
- Python中re模块中的split函数
- python中的split() strip() argv
- Python中的split()函数的使用方法
- Python中的split()函数的用法
- android 挂载 SDcard 的方法
- 使用TCP协议实现文件传输
- D3DXMatrixPerspectiveFovLH详解
- 使用servlet编写生成验证码
- mxl方法改变button的未选中、选中、点击时的图片
- Python中的split()
- [Effective Java Distilled] Item 1 考虑使用静态工厂方法来替换构造方法
- 使用activePDF Toolkit如何创建数字签名
- 排序算法入门之冒泡排序优化
- Debian 6.0.6 系统安装第五步: 安装GNOME
- quartz 使用
- 理解MySQL数据库覆盖索引
- 装饰模式
- 正确使用PresentModalViewController