Python 判断字符串是否含有指定字符or字符串

Python 判断字符串是否含有指定字符or字符串 ,有如下方法:

1、使用成员操作符 in 

str1= "ABCDEF123descsf"
str2= "CD"
result = str2 in str1
print(result)  # True

2、使用string模块的find()  rfind  index()  rindex()

猜你喜欢

转载自www.cnblogs.com/shenxiaolin/p/12602360.html
今日推荐