在Python中,我们可以使用in操作符来检查一个字符串是否包含另一个字符串。以下是一个例子:

string1 = "Hello, World!"
string2 = "Hello"

if string2 in string1:
    print("string1包含string2")
else:
    print("string1不包含string2")

在上面的例子中,string2 in string1表达式返回True,因为string2string1的一部分。因此,输出将是string1包含string2

py 字符串包含

原文地址: https://www.cveoy.top/t/topic/hQJ5 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录