• <legend id='UFNtK'><style id='UFNtK'><dir id='UFNtK'><q id='UFNtK'></q></dir></style></legend>

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

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

      1. 为什么我的函数不将值返回给全局变量?

        Why does my function not return value to global variable?(为什么我的函数不将值返回给全局变量?)

            <tbody id='Q0vbc'></tbody>
            <bdo id='Q0vbc'></bdo><ul id='Q0vbc'></ul>

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

              1. <tfoot id='Q0vbc'></tfoot>

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

                • 本文介绍了为什么我的函数不将值返回给全局变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  为什么 print(squared) 返回 0 而不是 100?

                  我以为从函数返回后-变量squared的值会被赋值给同名的全局变量?

                  I thought that after being returned from the function - the value of the variable squared would be assigned to the the global variable with the same name?

                  squared = 0
                  def square(n):
                      """Returns the square of a number."""
                      squared = n**2
                      print "%d squared is %d." % (n, squared)
                      return squared
                  
                  
                  square(10)
                  print(squared)
                  

                  返回:

                  推荐答案

                  将函数的结果赋值给变量:

                  Assign the result of the function to the variable:

                  squared = square(10)
                  

                  这就是在函数中使用 return squared 的重点,不是吗?

                  This is the whole point of using return squared in the function, isn't it?

                  这篇关于为什么我的函数不将值返回给全局变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  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='tOQZk'></bdo><ul id='tOQZk'></ul>
                        <tbody id='tOQZk'></tbody>

                        <legend id='tOQZk'><style id='tOQZk'><dir id='tOQZk'><q id='tOQZk'></q></dir></style></legend>

                          1. <tfoot id='tOQZk'></tfoot>
                          2. <small id='tOQZk'></small><noframes id='tOQZk'>

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