Python--判断字符串是否包含子字符串 发表于 2018-08-22 更新于 2019-01-17 分类于 Python 热度: Valine: 为方便以后开发查阅,特记录此相关代码。所要实现的功能: 判断字符串是否包含子字符串 方法一:In12345string = 'helloworld'if 'world' in string: print('Exist')else: print('Not exist') 方法二:Find12345string = 'helloworld'if string.find(’world‘) > -1: print('Exist')else: print('Not exist') 方法三:Index1234if string.index(’world‘) > -1: #因为-1的意思代表没有找到字符,所以判断>-1就代表能找到 print('Exist')else: print('Not exist') 但是,如果没找到,程序会抛出异常 🍭支持一根棒棒糖吧! 微信支付 支付宝 本文作者: 旋律信 本文链接: https://wangcong.net/article/PythonFindStrings.html 版权声明: 本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!