def subStringMatchExact(word,subword):
if len(word)<len(subword):
print 'substring is bigget than the string, please type another substring.'
return None
else:
for i in xrange(0,len(word)):
t =()
j = 0
while word[i] == subword[j]:
j = j+1
i = i+1
if j == len(subword):
t = t+(i-j,)
return t
print subStringMatchExact('afgbcdefg', 'fg')
如何讓循環再次啓動並保持跟蹤值i
?While循環與if語句
任何不使用'subword in word'和'word.index(subword)'的理由? – 2014-12-06 14:08:18
你是什麼意思「跟蹤'我'」? – rlms 2014-12-06 14:10:48
因此,當循環繼續時,由於if語句的原因,它保持離開它的點。 – chubaka 2014-12-06 14:13:47