<tfoot id='mdWDz'></tfoot>

    <legend id='mdWDz'><style id='mdWDz'><dir id='mdWDz'><q id='mdWDz'></q></dir></style></legend>
    • <bdo id='mdWDz'></bdo><ul id='mdWDz'></ul>

    1. <small id='mdWDz'></small><noframes id='mdWDz'>

    2. <i id='mdWDz'><tr id='mdWDz'><dt id='mdWDz'><q id='mdWDz'><span id='mdWDz'><b id='mdWDz'><form id='mdWDz'><ins id='mdWDz'></ins><ul id='mdWDz'></ul><sub id='mdWDz'></sub></form><legend id='mdWDz'></legend><bdo id='mdWDz'><pre id='mdWDz'><center id='mdWDz'></center></pre></bdo></b><th id='mdWDz'></th></span></q></dt></tr></i><div id='mdWDz'><tfoot id='mdWDz'></tfoot><dl id='mdWDz'><fieldset id='mdWDz'></fieldset></dl></div>
    3. 递归代码返回无

      时间:2023-09-02
        <bdo id='2152M'></bdo><ul id='2152M'></ul>

              <small id='2152M'></small><noframes id='2152M'>

              <i id='2152M'><tr id='2152M'><dt id='2152M'><q id='2152M'><span id='2152M'><b id='2152M'><form id='2152M'><ins id='2152M'></ins><ul id='2152M'></ul><sub id='2152M'></sub></form><legend id='2152M'></legend><bdo id='2152M'><pre id='2152M'><center id='2152M'></center></pre></bdo></b><th id='2152M'></th></span></q></dt></tr></i><div id='2152M'><tfoot id='2152M'></tfoot><dl id='2152M'><fieldset id='2152M'></fieldset></dl></div>
            • <tfoot id='2152M'></tfoot>

            • <legend id='2152M'><style id='2152M'><dir id='2152M'><q id='2152M'></q></dir></style></legend>
                <tbody id='2152M'></tbody>

              1. 本文介绍了递归代码返回无的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我真的不明白,为什么是代码

                I really do not understand, why the code

                def isIn(char, aStr): 
                    ms = len(aStr)/2
                    if aStr[ms] == char:
                        print 'i am here now'
                        return True
                    elif char>aStr[ms] and not ms == len(aStr)-1:
                        aStr = aStr[ms+1:]
                    elif char <aStr[ms] and not ms == 0:
                        aStr = aStr[0:ms]
                    else:
                        return False
                    isIn(char, aStr)
                
                print isIn('a', 'ab')
                

                确实继续返回 None.它打印我现在在这里",但它不返回 True,就像下一行所说的那样.为什么?

                does keep on returning None. it prints 'i am here now', but it does not return True, just as the next line says. Why?

                推荐答案

                你可能希望在最后一行有一个 return:

                You probably want a return on the last line:

                return isIn(char, aStr)
                

                没有它,函数会在没有看到 return 的情况下终止时简单地返回 None.

                Without it, the function simply returns None when it terminates without seeing a return.

                这篇关于递归代码返回无的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:return,return None,根本不返回? 下一篇:对列表中的所有元素进行平方

                相关文章

                  <bdo id='OdiMV'></bdo><ul id='OdiMV'></ul>
              2. <tfoot id='OdiMV'></tfoot>

                  <small id='OdiMV'></small><noframes id='OdiMV'>

                    <legend id='OdiMV'><style id='OdiMV'><dir id='OdiMV'><q id='OdiMV'></q></dir></style></legend>
                  1. <i id='OdiMV'><tr id='OdiMV'><dt id='OdiMV'><q id='OdiMV'><span id='OdiMV'><b id='OdiMV'><form id='OdiMV'><ins id='OdiMV'></ins><ul id='OdiMV'></ul><sub id='OdiMV'></sub></form><legend id='OdiMV'></legend><bdo id='OdiMV'><pre id='OdiMV'><center id='OdiMV'></center></pre></bdo></b><th id='OdiMV'></th></span></q></dt></tr></i><div id='OdiMV'><tfoot id='OdiMV'></tfoot><dl id='OdiMV'><fieldset id='OdiMV'></fieldset></dl></div>