Python 官方文档:入门教程 => 点击学习
(1).find()方法: python find() 方法检测字符串中是否包含子字符串 str ,如果指定 beg(开始) 和 end(结束) 范围,则检查是否包含在指定范围内,如果包含子字符串返回开始的索引值,否
python find() 方法检测字符串中是否包含子字符串 str ,如果指定 beg(开始) 和 end(结束) 范围,则检查是否包含在指定范围内,如果包含子字符串返回开始的索引值,否则返回-1。
看示例:
print(result3)string = 'this is string'
>>>result1 = string.find('is')
>>>print(result1)
2
>>>result2 = string.find('me')
>>>print(result2)
-1
>>>result3 = string.find(' ')
>>>print(result3)
4
函数原型:
str.find(str, beg=0, end=len(string))
参数描述:
返回值:
如果包含子字符串返回开始的索引值,否则返回-1。
看示例:
>>>string = 'this is string'
>>>result = 'is' in string
>>>print(result)
true
>>>result = 'is' not in string
>>>print(result)
False
--结束END--
本文标题: Python--判断一个字符串是否包含某
本文链接: https://www.lsjlt.com/news/184123.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-03-01
2024-03-01
2024-03-01
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0