Python基础教程笔记——第3章:使用字符串
2015-08-02 09:43
761 查看
字符串是不可修改的,标准序列操作(索引,分片,判断成员资格,求长度,取最大值
最小值)对字符串都是有效的。
格式化字符串,类似于C语言的输出是的感觉。
>>> format="hello %s %s are you ok?"
>>> value=("yanliang","24")
>>> print(format % value)
hello yanliang 24 are you ok?
find函数 a.find(s) >>> a.find('s',2) 设定了搜索的起始点 >>> a.find('s',1,2) 设置了起始点和结束点
join函数 >>> sep='+' >>> seq=['1','2','3','4','5'] >>> sep.join(seq) 将sep分别的插入到seq中间
‘1+2+3+4+5’
lower函数 >>> a="HHGHGJ" >>> a.lower() 'hhghgj' 返回字符串的小写字母版
replace函数 >>> a="HHGHGJ" >>> a.replace('H','h') 'hhGhGJ' 将字符串中的H都用h代替
split函数 join的逆方法,将字符串分割成片
>>> a='1+2+3+4+5' >>> a.split('+') ['1', '2', '3', '4', '5']
strip函数 删除字符串两侧(不包括内部)空的字符串
>>> a='asi ' >>> a.strip() 'asi'
translate函数
最小值)对字符串都是有效的。
格式化字符串,类似于C语言的输出是的感觉。
>>> format="hello %s %s are you ok?"
>>> value=("yanliang","24")
>>> print(format % value)
hello yanliang 24 are you ok?
find函数 a.find(s) >>> a.find('s',2) 设定了搜索的起始点 >>> a.find('s',1,2) 设置了起始点和结束点
join函数 >>> sep='+' >>> seq=['1','2','3','4','5'] >>> sep.join(seq) 将sep分别的插入到seq中间
‘1+2+3+4+5’
lower函数 >>> a="HHGHGJ" >>> a.lower() 'hhghgj' 返回字符串的小写字母版
replace函数 >>> a="HHGHGJ" >>> a.replace('H','h') 'hhGhGJ' 将字符串中的H都用h代替
split函数 join的逆方法,将字符串分割成片
>>> a='1+2+3+4+5' >>> a.split('+') ['1', '2', '3', '4', '5']
strip函数 删除字符串两侧(不包括内部)空的字符串
>>> a='asi ' >>> a.strip() 'asi'
translate函数
相关文章推荐
- contos系统升级最新python版本
- Python基础教程笔记——第2章:列表和元组
- python爬虫 爬取淘女郎介绍以及照片
- 【Python】virtualenv —— 建立Python虚拟环境
- mysql-python安装时EnvironmentError: mysql_config not found
- python用法——Mixin
- chardet字符集检测模块
- Python3——简单获取网页文字的爬虫
- Python Requests快速入门
- Python ,pickle
- python中基于descriptor的一些概念(下)
- python中基于descriptor的一些概念(上)
- Python学习之条件语句
- Pyhon2与Python3 ——urllib2
- python爬虫(三)--Python的set()
- wxPython中菜单、按钮学习
- Python编程学习——拷贝
- python ,__set__, __get__ 等解释
- Python几行代码就控制了FTP
- Python简单的爬虫