python如何判断字符串的包含关系,比如 xuexi 包含于 xuexihao

2024-12-16 17:33:09
推荐回答(3个)
回答1:

#!/usr/local/bin/python
str1 = "xuerui"
str2 = "xueruihao"
if str1 in str2:
print "yes"
else:
print "no"

回答2:

使用成员检查符 in .

>>> a = 'xuexi'
>>> b = 'xuexihao'
>>> a in b
True

回答3:

xuexi in xuexihao