首页>>帮助中心>>香港vps服务器的python中find函数是什么意思

香港vps服务器的python中find函数是什么意思

2023/10/19 429次

香港vps服务器的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

一诺网络香港免备案专区,提供「香港增强VPS」和「香港特惠VPS」两种类型的高可用弹性计算服务,搭载新一代英特尔®至强®铂金处理器,接入CN2低延时高速回国带宽线路,网络访问顺滑、流畅。机房网络架构采用了BGP协议的解决方案可提供多线路互联融合网络,使得不同网络运营商线路的用户都能通过最佳路由实现快速访问。香港云VPS低至29/月,购买链接:https://www.enuoidc.com/vps.html?typeid=2