擅长:python、mysql、java
<p>如果函数体外部存在<code>lastindex</code>,则可以引用函数顶部的全局变量。lastindex必须全局存在或通过递归向下传递。还记得在递归步骤中添加return语句。见下文:</p>
<pre><code>def find_postpep_site(string):
global lastindex #added
if(re.search('(G[RK])|(GKR)|(G$)', string)):
lastindex = (re.search('(G[RK])|(GKR)|(G$)', string)).end()
return find_postpep_site(string[lastindex:10000])
else:
return lastindex
</code></pre>