python在字符串中查找子字符串的简单方法

2022-03-11 00:00:00 简单 字符串 查找

python在字符串中查找子字符串,如果找到则返回子字符串的位置,如果没有找到则返回-1

"""
作者:皮蛋编程(https://www.pidancode.com)
创建日期:2022/3/21
功能描述:python在字符串中查找子字符串
"""
S = 'www.pidancode.com'
where = S.find('pidan')
print(where)

输出:4

以上代码在python3.9环境下测试通过

相关文章