python学习笔记(三)字符串
来源:互联网 发布:怎么查淘宝等级手机 编辑:程序博客网 时间:2024/05/17 07:57
字符串的一些重要方法方法
find(),返回子串所在位置的最左端索引,若找不到则返回-1。
join(),是split()方法的逆方法,用来在队列中添加元素。
seq = ['1', '2', '3']sep = '/'print sep.join(seq)sep = '\\'print sep.join(seq)运行结果:
运行结果:
1/2/3
1\2\3
lower(),返回字符串的小写字母版。
replace(string a,string b),返回某字符串a的所有匹配项均被替换成b之后得到的字符串。
split(),将字符串分割成序列。
strip(),去除两侧(不包括内部)的字符串。
translate(),同时进行多个单个字符的替换。
以下是测试程序
# -*- coding:utf-8 -*-'''Created on 2013-7-7@author: GinSmile'''from string import maketransmyStr = ' !This is a simple. !! 'myStr = myStr.strip(' !') #去除两边空格和叹号print myStr #This is a simple.print myStr.lower() #this is a simple.print myStr.capitalize() #This is a simple.print myStr.upper() #THIS IS A SIMPLE.seq = myStr.split(' ')print seq #['this', 'is', 'a', 'simple.']print ' '.join(seq) #this is a simple.table = maketrans('cs', 'kz')print len(table) #256print table[97:123] #abkdefghijklmnopqrztuvwxyz#以上,table作为转换表编写成功print 'this is another simple. cut the hair~~'.translate(table) #thiz iz another zimple. kut the hair~~
- python学习笔记(三)字符串
- python学习笔记(六):字符串(三)
- 简明python教程学习笔记(三)-字符串
- Python学习笔记(三)——字符串
- Python学习笔记(三)英文字符串的大小写转换
- Python 学习笔记(三) 使用字符串
- 3. Python脚本学习笔记三字符串
- Python学习笔记【三】——《python基础教程》:: 使用字符串
- python学习笔记(三)
- Python学习笔记(三)
- python学习笔记(三)
- python学习笔记:(三)
- Python学习笔记(三)
- python学习笔记(三)
- Python学习笔记(三)
- python 学习笔记(三)
- python学习笔记(三)
- Python学习笔记(三)
- 某公司java开发面试题
- Poj_1068 Parencodings
- Web Storage:sessionStorage与localStorage
- 选择合适你的电源-开关电源入门讲解
- 镜像站点
- python学习笔记(三)字符串
- Cas代理报错error.authentication.credentials.bad
- CURL模拟访问网页(转)
- ibatis 实现一对一和一对多(2)
- EXCEL中的高级技巧—之一
- JAVAEE listener总结
- codeforces 327D Block Tower
- 确定SEO目标,定义网站受众
- 初探,tty console uart的三角关系