Python判断一个字符串是否包含某个指定的字符串
成员操作符 in
str = "string test string test" find1 = "str" find2 = "test" print(find1 in str) # True print(find1 not in str) # False
偷偷说一句:in不只是在字符串中可以使用哦!期待后面的教程叭
使用字符串对象的 find() 、 rfind() 、 index() 、rindex()、 count()
str = "string test string test" find1 = "str" find2 = "test" # find print(str.find(find1)) # 0 print(str.find(find2)) # 7 # rfind print(str.rfind(find1)) # 12 print(str.rfind(find2)) # 19 # index print(str.index(find1)) # 0 print(str.index(find2)) # 7 # rindex print(str.rindex(find1)) # 12 print(str.rindex(find2)) # 19 # count print(str.count(find1)) # 2 print(str.count(find2)) # 2
相关推荐
文山羊 2020-10-20
Tristahong 2020-10-14
PYTandFA 2020-09-15
fengzhiwu 2020-08-01
kkpiece 2020-07-08
银角大王 2020-07-05
shonmark 2020-06-27
meltsnow 2020-06-08
shengge0 2020-06-01
fanhuasijin 2020-05-30
hanxia 2020-05-28
kkpiece 2020-05-28
星辰大海的路上 2020-05-01
xiaoxiaoniaoer 2020-04-26
sschencn 2020-04-11
waiwaiLILI 2020-03-20
dxbjfu0 2020-03-06
逍遥友 2020-03-03
Morelia 2020-03-03