千家信息网

python中的find函数怎么用

发表于:2024-10-12 作者:千家信息网编辑
千家信息网最后更新 2024年10月12日,这篇文章主要讲解了"python中的find函数怎么用",文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习"python中的find函数怎么用"吧!具体使用步
千家信息网最后更新 2024年10月12日python中的find函数怎么用

这篇文章主要讲解了"python中的find函数怎么用",文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习"python中的find函数怎么用"吧!

具体使用步骤:

1、首先打开python编辑器,新建一个python项目。

2、在python项目中定义2个字符串。


str1 = "this is string example....wow!!!";
str2 = "exam";

3、再使用find函数检测字符串str1中是否包含子字符串str2并返回索引值。


print str1.find(str2);

返回结果:


15

相关示例代码:


mystring = "Meet Guru99 Tutorials Site.Best site for Python Tutorials!"
print("The position of Best site is at:", mystring.find("Best site", 5, 40))
print("The position of Guru99 is at:", mystring.find("Guru99", 20))


#输出结果
The position of Best site is at: 27
The position of Guru99 is at: -1

感谢各位的阅读,以上就是"python中的find函数怎么用"的内容了,经过本文的学习后,相信大家对python中的find函数怎么用这一问题有了更深刻的体会,具体使用情况还需要大家实践验证。这里是,小编将为大家推送更多相关知识点的文章,欢迎关注!

0