find Python · 字符串方法
查找子串第一次出现的位置,找不到返回 -1。
怎么用
字符串.find(子串)
小例子
print('hello'.find('l'))
运行结果
2
官方文档:https://docs.python.org/zh-cn/3/library/stdtypes.html#string-methods
在代码里遇到不认识的词?打开代码点读机,点一下就懂 → ← Python全部词条find Python · 字符串方法查找子串第一次出现的位置,找不到返回 -1。
字符串.find(子串)
print('hello'.find('l'))
2
官方文档:https://docs.python.org/zh-cn/3/library/stdtypes.html#string-methods
在代码里遇到不认识的词?打开代码点读机,点一下就懂 → ← Python全部词条