def countSubStringMatchRecursive(target,key):
"""Counts how many times key is in string(string,key)"""
x=find(target,key)
print x
return x!=-1 and countSubStringMatchRecursive(target[x+1:],key)+1
所以这个程序接受一个给定的字符串并计算一个子字符串在其中出现的次数。因此,给定目标“香蕉”和键“an”,该函数将输出 2。
我有点困惑它是如何做到这一点的。x!=1 是否使程序只返回 x 不等于 1?我假设 countSubStringMatchRecursive... 末尾的 +1 以某种方式计数。