<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. 递归代码返回无

      Recursive code returns None(递归代码返回无)
        <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.

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

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                Initialize Multiple Numpy Arrays (Multiple Assignment) - Like MATLAB deal()(初始化多个 Numpy 数组(多重赋值) - 像 MATLAB deal())
                How to extend Python class init(如何扩展 Python 类初始化)
                What#39;s the difference between dict() and {}?(dict() 和 {} 有什么区别?)
                What is a wrapper_descriptor, and why is Foo.__init__() one in this case?(什么是 wrapper_descriptor,为什么 Foo.__init__() 在这种情况下是其中之一?)
                Initialize list with same bool value(使用相同的布尔值初始化列表)
                setattr with kwargs, pythonic or not?(setattr 与 kwargs,pythonic 与否?)
                  <bdo id='OdiMV'></bdo><ul id='OdiMV'></ul>
                  <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>
                          <tbody id='OdiMV'></tbody>
                        • <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>