python 查找字符串是否存在实例详解,python实例
python 查找字符串是否存在实例详解,python实例
python中查找指定的字符串的方法如下:
code
#查询 def selStr(): sStr1 = 'jsjtt.com' sStr2 = 'com' #index查询某个字符串,返回索引 nPos = sStr1.index(sStr2) if(nPos >=0): print 'sStr1中包括sStr2中的字符' print nPos #find 方法如果没有查询到返回-1 nPos2 = sStr1.find('abc') print nPos2 #查询到返回字符所在位置 print sStr1.find('com') selStr();
python分割字符串
def split(): sStr1 = 'ab,cde,fgh,ijk' sStr2 = ',' #用find查找逗号所在的索引位置 sStr1 = sStr1[sStr1.find(sStr2) + 1:] print sStr1 #使用split函数分割字符串 s = 'ab,cde,fgh,ijk' result = s.split(',') print(result) print(result[0]) split();
感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!
相关内容
- Python使用中文正则表达式匹配指定中文字符串的方法示
- python dict 字典 以及 赋值 引用的一些实例(详解),pyth
- linux平台使用Python制作BT种子并获取BT种子信息的方法,
- python去掉行尾的换行符方法,python行尾换行符
- python去除空格和换行符的实现方法(推荐),python换行
- 完美解决Python2操作中文名文件乱码的问题,
- python 捕获shell脚本的输出结果实例,pythonshell
- python fabric实现远程部署,pythonfabric部署
- Python网络爬虫出现乱码问题的解决方法,python爬虫
- Python socket网络编程TCP/IP服务器与客户端通信,pythonso
评论关闭