如何检查给定的 Python 字符串是否是另一个字符串的子字符串? [英] How do I check if a given Python string is a substring of another one?

查看:97
本文介绍了如何检查给定的 Python 字符串是否是另一个字符串的子字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个字符串,我想检查第一个字符串是否是另一个字符串的子字符串.Python 有这样的内置功能吗?

解决方案

尝试使用 in 像这样:

<预><代码>>>>x = '你好'>>>y = '会'>>>y 在 x真的

I have two strings and I would like to check whether the first is a substring of the other. Does Python have such a built-in functionality?

解决方案

Try using in like this:

>>> x = 'hello'
>>> y = 'll'
>>> y in x
True

这篇关于如何检查给定的 Python 字符串是否是另一个字符串的子字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆