久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

  • <legend id='4G8Pv'><style id='4G8Pv'><dir id='4G8Pv'><q id='4G8Pv'></q></dir></style></legend>
    <tfoot id='4G8Pv'></tfoot>

      <small id='4G8Pv'></small><noframes id='4G8Pv'>

        <bdo id='4G8Pv'></bdo><ul id='4G8Pv'></ul>

      1. <i id='4G8Pv'><tr id='4G8Pv'><dt id='4G8Pv'><q id='4G8Pv'><span id='4G8Pv'><b id='4G8Pv'><form id='4G8Pv'><ins id='4G8Pv'></ins><ul id='4G8Pv'></ul><sub id='4G8Pv'></sub></form><legend id='4G8Pv'></legend><bdo id='4G8Pv'><pre id='4G8Pv'><center id='4G8Pv'></center></pre></bdo></b><th id='4G8Pv'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='4G8Pv'><tfoot id='4G8Pv'></tfoot><dl id='4G8Pv'><fieldset id='4G8Pv'></fieldset></dl></div>
      2. 未綁定的變量和名稱

        Unbound variable and name(未綁定的變量和名稱)
      3. <small id='gH4Pk'></small><noframes id='gH4Pk'>

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

          <tfoot id='gH4Pk'></tfoot>
          <i id='gH4Pk'><tr id='gH4Pk'><dt id='gH4Pk'><q id='gH4Pk'><span id='gH4Pk'><b id='gH4Pk'><form id='gH4Pk'><ins id='gH4Pk'></ins><ul id='gH4Pk'></ul><sub id='gH4Pk'></sub></form><legend id='gH4Pk'></legend><bdo id='gH4Pk'><pre id='gH4Pk'><center id='gH4Pk'></center></pre></bdo></b><th id='gH4Pk'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='gH4Pk'><tfoot id='gH4Pk'></tfoot><dl id='gH4Pk'><fieldset id='gH4Pk'></fieldset></dl></div>
              <tbody id='gH4Pk'></tbody>

                • <bdo id='gH4Pk'></bdo><ul id='gH4Pk'></ul>

                  本文介紹了未綁定的變量和名稱的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  根據python參考手冊我們有

                  當根本找不到名稱時,會引發 NameError 異常.如果該名稱指的是尚未綁定的局部變量,a引發 UnboundLocalError 異常.UnboundLocalError 是一個子類的名稱錯誤.

                  When a name is not found at all, a NameError exception is raised. If the name refers to a local variable that has not been bound, a UnboundLocalError exception is raised. UnboundLocalError is a subclass of NameError.

                  我不明白什么時候拋出 UnboundLocalError?因為

                  I don't to understand when the UnboundLocalError is thrown? Because

                  Python 缺少聲明并允許發生名稱綁定操作代碼塊內的任何位置.

                  Python lacks declarations and allows name binding operations to occur anywhere within a code block.

                  那么我們怎樣才能聲明一個變量,而不是初始化她呢?

                  So how we can declare a variable, but not to initialize her?

                  推薦答案

                  你可以引用一個沒有分配的名字:

                  You can refer to a name without having assigned to it:

                  >>> foobar
                  Traceback (most recent call last):
                    File "<stdin>", line 1, in <module>
                  NameError: name 'foobar' is not defined
                  

                  這里 foobar 被引用,但從未被分配到.這會引發 NameError 因為名稱從未綁定.

                  Here foobar is being referred to, but was never assigned to. This raises a NameError because the name was never bound.

                  更微妙的是,這里沒有發生分配,因為執行的行永遠不會運行:

                  More subtly, here assignment is not happening because the line that does is never run:

                  >>> def foo():
                  ...     if False:
                  ...         spam = 'eggs'
                  ...     print spam
                  ... 
                  >>> foo()
                  Traceback (most recent call last):
                    File "<stdin>", line 1, in <module>
                    File "<stdin>", line 4, in foo
                  UnboundLocalError: local variable 'spam' referenced before assignment
                  

                  因為 spam = 'eggs' 永遠不會執行,所以 print spam 會引發 UnboudLocalError.

                  Because spam = 'eggs' is never executed, print spam raises an UnboudLocalError.

                  請注意,Python 中沒有任何地方聲明過.您綁定或不綁定,聲明不是語言的一部分.

                  Note that nowhere in Python is a name ever declared. You bind or don't bind, declaration is not part of the language.

                  相反,binding 用于確定名稱的范圍;綁定操作包括賦值、用于 for 循環的名稱、函數參數、導入語句、在 except 子句中保存捕獲的異常的名稱、上下文管理器的名稱一個 with 語句所有的綁定名稱.

                  Instead, binding is used to determine the scope of a name; binding operations include assignment, names used for a for loop, function parameters, import statements, name to hold a caught exception in an except clause, the name for a context manager in a with statement all bind names.

                  如果名稱綁定在范圍內(例如在函數中),則它是本地名稱,除非您使用 global 語句(或 nonlocal 語句在 Python 3 中)將名稱顯式標記為全局(或閉包).

                  If a name is bound in a scope (such as in a function) then it is a local name, unless you use a global statement (or a nonlocal statement in Python 3) to explicitly mark the name as a global (or a closure) instead.

                  所以下面是一個錯誤:

                  >>> foo = None
                  >>> def bar():
                  ...     if False:
                  ...         foo = 'spam'
                  ...     print foo
                  ... 
                  >>> bar()
                  Traceback (most recent call last):
                    File "<stdin>", line 1, in <module>
                    File "<stdin>", line 4, in bar
                  UnboundLocalError: local variable 'foo' referenced before assignment
                  

                  因為 foosomewhere 綁定在 bar 函數范圍內.但是如果您將 foo 標記為全局,則該函數可以工作:

                  because foo is being bound somewhere in the bar function scope. But if you mark foo as a global, the function works:

                  >>> foo = None
                  >>> def bar():
                  ...     global foo
                  ...     if False:
                  ...         foo = 'spam'
                  ...     print foo
                  ... 
                  >>> bar()
                  None
                  

                  因為現在 Python 編譯器知道您希望 foo 改為全局變量.

                  because now the Python compiler knows you wanted foo to be a global instead.

                  所有這些都記錄在 命名和綁定部分 Python 參考文檔.

                  This is all documented in the Naming and Binding section of the Python reference documentation.

                  這篇關于未綁定的變量和名稱的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                  【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                  相關文檔推薦

                  python: Two modules and classes with the same name under different packages(python:不同包下同名的兩個模塊和類)
                  Configuring Python to use additional locations for site-packages(配置 Python 以使用站點包的其他位置)
                  How to structure python packages without repeating top level name for import(如何在不重復導入頂級名稱的情況下構造python包)
                  Install python packages on OpenShift(在 OpenShift 上安裝 python 包)
                  How to refresh sys.path?(如何刷新 sys.path?)
                  Distribute a Python package with a compiled dynamic shared library(分發帶有已編譯動態共享庫的 Python 包)
                    <tbody id='DL2bp'></tbody>

                • <legend id='DL2bp'><style id='DL2bp'><dir id='DL2bp'><q id='DL2bp'></q></dir></style></legend>
                    <bdo id='DL2bp'></bdo><ul id='DL2bp'></ul>
                    <i id='DL2bp'><tr id='DL2bp'><dt id='DL2bp'><q id='DL2bp'><span id='DL2bp'><b id='DL2bp'><form id='DL2bp'><ins id='DL2bp'></ins><ul id='DL2bp'></ul><sub id='DL2bp'></sub></form><legend id='DL2bp'></legend><bdo id='DL2bp'><pre id='DL2bp'><center id='DL2bp'></center></pre></bdo></b><th id='DL2bp'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='DL2bp'><tfoot id='DL2bp'></tfoot><dl id='DL2bp'><fieldset id='DL2bp'></fieldset></dl></div>
                        • <small id='DL2bp'></small><noframes id='DL2bp'>

                            <tfoot id='DL2bp'></tfoot>
                            主站蜘蛛池模板: 欧美日韩高清免费 | 欧美一区二区三区 | 黄毛片 | 毛片一区二区三区 | 黄色大片网| 一级在线毛片 | 久久久久国产 | 特一级毛片| 国产精品成人一区二区三区 | 久久国产精品网站 | 国产成人精品一区二区三区网站观看 | 亚洲成av片人久久久 | 国产福利在线播放麻豆 | 国产一区二区三区免费观看在线 | 欧美一级欧美一级在线播放 | 久久不卡| 北条麻妃av一区二区三区 | 久在线视频播放免费视频 | 久久国产精品亚洲 | 麻豆精品一区二区三区在线观看 | 欧美乱大交xxxxx另类电影 | 古装人性做爰av网站 | 九九热免费看 | 国产日韩欧美一区二区 | 蜜桃免费一区二区三区 | 日本一区二区三区四区 | 亚洲 中文 欧美 日韩 在线观看 | 亚洲成在线观看 | 久久com| 久久精品av麻豆的观看方式 | 免费高清av | 毛片软件| 日韩av电影院 | 久久久蜜臀国产一区二区 | 久久久妇女国产精品影视 | 国产一区二区久久 | 亚洲欧洲小视频 | 日韩成人av在线播放 | 高清欧美性猛交xxxx黑人猛交 | 国产日韩免费观看 | 成人免费视频网站在线看 |