互联网技术 / 互联网资讯 · 2024年3月15日

Python3云计算开发中的find()方法详解

描述

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

语法

以下是 find() 方法语法:

stR.find(stR, beg=0, end=len(stRing))

参数

stR — 指定检索的字符串

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

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

返回值

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

实例

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

以上实例输出结果如下:

OpenMagic API

Need more than content? Move into the product flow.

If you are here for model access, pricing, developer docs, or the future API console, the dedicated product path now lives on api.openmagic.ai.

登录免费注册