Python字符串方法find()确定字符串str是否出现在字符串中,或者如果给定起始索引beg和结束索引end,则字符串出现在字符串的子串中。
str.find(str, beg=0, end=len(string))
str - 这指定要搜索的字符串。
beg - 这是起始索引,默认情况下为0。
end - 这是结束索引,默认情况下等于字符串的长度。
如果找到索引,则为-1。
#!/usr/bin/python str1="this is string example....wow!!!"; str2="exam"; print str1.find(str2) print str1.find(str2, 10) print str1.find(str2, 40)
运行上面代码输出
15 15 -1
祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)