Python find函数用法和概念
2023-09-11 14:17:11 时间
概念:
Python find() 方法检测字符串中是否包含子字符串 str ,如果指定 beg(开始) 和 end(结束) 范围,则检查是否包含在指定范围内,如果包含子字符串返回开始的索引值,否则返回-1。
语法
find()方法语法:
str.find(str, beg=0, end=len(string))
参数
- str -- 指定检索的字符串
- beg -- 开始索引,默认为0。
- end -- 结束索引,默认为字符串的长度。
返回值
如果包含子字符串返回开始的索引值,否则返回-1。
实例
下面的实例可以基本覆盖find的用法:
1 #!/usr/bin/python 2 3 str1 = "this is string example....wow!!!"; 4 str2 = "exam"; 5 6 print str1.find(str2); 7 print str1.find(str2, 10); 8 print str1.find(str2, 40); 9 10 info = 'abca' 11 print info.find('a') 12 print info.find('a',1) 13 print info.find('3') 14 print info.find('1') 15 print info.find('c') 16 ~
运行结果:
15
15
-1
0
3
-1
-1
2
相关文章
- Python 应用自动化部署工具Fabirc
- 当Python遇到Andriod手机 万物皆可盘
- Python 日期和时间_python 当前日期时间_python日期格式化
- 欠拟合与过拟合、泛化能力概念总结及python示例
- paip.python 执行shell 带空格命令行attilax总结
- Python语言学习之打印输出那些事:python输出图表和各种吊炸天的字符串或图画、版权声明(如README.md)等之详细攻略
- Python编程语言学习:python编程语言中重要函数讲解之map函数等简介、使用方法之详细攻略
- Python编程语言学习:python语言中快速查询python自带模块&函数的用法及其属性方法、如何查询某个函数&关键词的用法、输出一个类或者实例化对象的所有属性和方法名之详细攻略
- Python之tkinter:动态演示调用python库的tkinter带你进入GUI世界(Button的command/Label/PhotoImage/封装为类)
- Python之多线程:python多线程设计之同时执行多个函数命令详细攻略
- 已解决2. Set PROTOCOL_BUPFERS_PYTHON_iMPLEMENTATION=python (but this will use pure-Python parsing and w
- python基础知识之 Python代码规范
- 房屋千千万,如何找到便宜实惠的呢,python采集数据并做数据可视化~
- 从零开始学python | 使用Python映射,过滤和缩减函数:所有您需要知道的
- 【阶段一】Python快速入门01篇:Python基础环境、Python基础概念、字符串常用操作
- Python编程:shelve模块-持久化python数据
- Python编程:python面向对象
- Python编程:命令行python和python -m的区别
- python基础===pendulum '''Python datetimes made easy.'''
- python基础===Python性能优化的20条建议
- Python实现的一个简单LRU cache
- 【Leetcode刷题Python】70. 爬楼梯
- 【异常】前端ERR! stack Error: Can‘t find Python executable “python“, you can set the PYTHON env variable.
- 〖Python自动化办公篇㉑〗- python实现邮件自动化 - 定时发送邮件
- python开发岗位需求分析,来看看它是什么一个情况吧
- 【Python实战】 ---- python 实现 CSDN 的定时自动签到