• <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. 为什么我的函数不将值返回给全局变量?

        时间:2023-09-02

            <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?

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

                  上一篇:Python如何从一个函数返回多个值? 下一篇:Python - 函数返回值

                  相关文章

                    <bdo id='tOQZk'></bdo><ul id='tOQZk'></ul>

                  <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>