2022
我们一起努力

python中find函数是什么意思

pythonfind函数是实现检索字符串并且输出运算值的意思,语法格式为:“str.find(str, beg=0, end=len(string))”,这里“str”代表指定检索的字符串、“beg”代表开始索引,默认为0、“end”代表结束索引,默认为字符串的长度。

具体使用步骤:

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

赞(0)
文章名称:《python中find函数是什么意思》
文章链接:https://www.fzvps.com/91226.html
本站文章来源于互联网,如有侵权,请联系管理删除,本站资源仅供个人学习交流,请于下载后24小时内删除,不允许用于商业用途,否则法律问题自行承担。
图片版权归属各自创作者所有,图片水印出于防止被无耻之徒盗取劳动成果的目的。

评论 抢沙发

评论前必须登录!