教程集 www.jiaochengji.com
教程集 >  Python编程  >  Python入门  >  正文 Python find()方法

Python find()方法

发布时间:2021-12-11   编辑:jiaochengji.com
教程集为您提供Python find()方法等资源,欢迎您收藏本站,我们将为您提供最新的Python find()方法资源

描述

Python find() 方法检测字符串中是否包含子字符串 str ,如果指定 beg(开始) 和 end(结束) 范围,则检查是否包含在指定范围内,如果包含子字符串返回开始的索引值,否则返回-1。

语法

find()方法语法:

<pre class="brush:html;toolbar:false">str.find(str, beg=0 end=len(string))</pre>

参数

str -- 指定检索的字符串

beg -- 开始索引,默认为0。

end -- 结束索引,默认为字符串的长度。

返回值

如果包含子字符串返回开始的索引值,否则返回-1。

实例

以下实例展示了find()方法的实例:

<pre class="brush:html;toolbar:false;">#!/usr/bin/python   str1 = "this is string example....wow!!!"; str2 = "exam";   print str1.find(str2); print str1.find(str2, 10); print str1.find(str2, 40);</pre>

以上实例输出结果如下:

<pre class="brush:html;toolbar:false">15 15 -1</pre>

<span style="color: rgb(0, 0, 0); font-family: Verdana, sans-serif; font-size: 15px; white-space: normal; background-color: rgb(255, 255, 255);">
</span>

您可能感兴趣的文章:
python中的find函数怎么用
python如何删除缓存文件
Python find()方法
PHP启动报错 php提示SNMP错误的解决方法
Python find()方法:检测字符串中是否包含某子串
jQuery初学:find()方法及children方法的区别分析
python中index是什么意思
python index函数是什么意思
Yii 2.0框架数据增删改查的操作
JQuery实现表格中相同单元格合并示例代码

[关闭]
~ ~