Python String find() 方法
find()
方法返回子字符串第一次出现的索引(如果找到)。如果未找到,则返回 -1。
示例
message = 'Python is a fun programming language'
# 检查 'fun' 的索引
print(message.find('fun'))
# 输出: 12
find() 语法
find()
方法的语法是:
str.find(sub[, start[, end]] )
find() 参数
find()
方法最多接受三个参数:
- sub - 要在 str 字符串中搜索的子字符串。
- start 和 end(可选)- 在此范围
str[start:end]
内搜索子字符串。