在 Python 中,可以使用 'in' 运算符来判断一个字符串是否包含另一个字符串。

例如:

string1 = 'Hello, World!'
string2 = 'Hello'

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

输出结果是:string1包含string2


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

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