首页 > 编程语言 >python 中字符串 内置函数 find

python 中字符串 内置函数 find

时间:2022-08-14 17:12:04浏览次数:51  
标签:内置 匹配 python str1 ## ab 字符串 find

 

001、

>>> str1 = "xabdxyabxykk"          ## 测试字符串
>>> str1
'xabdxyabxykk'
>>> str1.find("ab")                ## 返回测试字符串中首次匹配ab的首字符的索引
1
>>> str1.find("ab", 3)             ## 指定在字符串中匹配的起始位置为3, 返回首次匹配的首字符索引
6
>>> str1.find("xy")
4
>>> str1.find("xy", 5)
8
>>> str1.find("mn")                ## 没有匹配项时, 返回  -1
-1

 

标签:内置,匹配,python,str1,##,ab,字符串,find
From: https://www.cnblogs.com/liujiaxin2018/p/16585785.html

相关文章