承接国内外服务器租用托管、定制开发、网站代运营、网站seo优化托管接单、网站代更新,新老站点皆可!!咨询QQ:3787320601
当前位置:首页  >  互联网圈  >  python中find函数是什么意思

python中find函数是什么意思

管理员 2023-03-23 10:03:56 互联网圈 64 ℃ 0 评论 1348字 收藏

python中find函数是甚么意思

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

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: ⑴

文章来源:丸子建站

文章标题:python中find函数是什么意思

https://www.wanzijz.com/view/2300.html

相关文章

Related articles

X

截屏,微信识别二维码

微信号:weimawl

(点击微信号复制,添加好友)

打开微信