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

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

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

      <tfoot id='Gqstu'></tfoot>
      <legend id='Gqstu'><style id='Gqstu'><dir id='Gqstu'><q id='Gqstu'></q></dir></style></legend>

      <i id='Gqstu'><tr id='Gqstu'><dt id='Gqstu'><q id='Gqstu'><span id='Gqstu'><b id='Gqstu'><form id='Gqstu'><ins id='Gqstu'></ins><ul id='Gqstu'></ul><sub id='Gqstu'></sub></form><legend id='Gqstu'></legend><bdo id='Gqstu'><pre id='Gqstu'><center id='Gqstu'></center></pre></bdo></b><th id='Gqstu'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='Gqstu'><tfoot id='Gqstu'></tfoot><dl id='Gqstu'><fieldset id='Gqstu'></fieldset></dl></div>
      1. Python3 的“函數注釋"有什么好的用途?

        What are good uses for Python3#39;s quot;Function Annotationsquot;?(Python3 的“函數注釋有什么好的用途?)

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

              <tbody id='7BNbb'></tbody>
            • <tfoot id='7BNbb'></tfoot>
              • <bdo id='7BNbb'></bdo><ul id='7BNbb'></ul>

                  本文介紹了Python3 的“函數注釋"有什么好的用途?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  函數注釋:PEP-3107

                  我遇到了一段演示 Python3 函數注釋的代碼片段.這個概念很簡單,但我想不出為什么這些是在 Python3 中實現的,或者它們有什么好的用途.也許SO可以啟發我?

                  I ran across a snippet of code demonstrating Python3's function annotations. The concept is simple but I can't think of why these were implemented in Python3 or any good uses for them. Perhaps SO can enlighten me?

                  它是如何工作的:

                  def foo(a: 'x', b: 5 + 6, c: list) -> max(2, 9):
                      ... function body ...
                  

                  參數后冒號后面的所有內容都是注解",->后面的信息是函數返回值的注解.

                  Everything following the colon after an argument is an 'annotation', and the information following the -> is an annotation for the function's return value.

                  foo.func_annotations 會返回一個字典:

                  foo.func_annotations would return a dictionary:

                  {'a': 'x',
                   'b': 11,
                   'c': list,
                   'return': 9}
                  

                  提供這個有什么意義?

                  推薦答案

                  我覺得這真的很棒.

                  來自學術背景,我可以告訴您,注釋已證明它們對于為 Java 等語言啟用智能靜態分析器非常寶貴.例如,您可以定義諸如狀態限制、允許訪問的線程、架構限制等語義,并且有相當多的工具可以讀取并處理它們,以提供超出您從編譯器獲得的保證的保證.你甚至可以編寫檢查前置條件/??后置條件的東西.

                  Coming from an academic background, I can tell you that annotations have proved themselves invaluable for enabling smart static analyzers for languages like Java. For instance, you could define semantics like state restrictions, threads that are allowed to access, architecture limitations, etc., and there are quite a few tools that can then read these and process them to provide assurances beyond what you get from the compilers. You could even write things that check preconditions/postconditions.

                  我覺得在 Python 中尤其需要這樣的東西,因為它的類型較弱,但實際上沒有任何結構可以讓這種簡單直接成為官方語法的一部分.

                  I feel something like this is especially needed in Python because of its weaker typing, but there were really no constructs that made this straightforward and part of the official syntax.

                  除了保證之外,注釋還有其他用途.我可以看到如何將基于 Java 的工具應用到 Python.例如,我有一個工具可以讓您為方法分配特殊警告,并在您調用它們時提示您應該閱讀它們的文檔(例如,假設您有一個不能以負值調用的方法,但它是從名稱上看不直觀).使用注釋,我可以在技術上為 Python 編寫類似的東西.同樣的,如果有官方的語法,也可以寫出一個基于標簽組織大類中方法的工具.

                  There are other uses for annotations beyond assurance. I can see how I could apply my Java-based tools to Python. For instance, I have a tool that lets you assign special warnings to methods, and gives you indications when you call them that you should read their documentation (E.g., imagine you have a method that must not be invoked with a negative value, but it's not intuitive from the name). With annotations, I could technically write something like this for Python. Similarly, a tool that organizes methods in a large class based on tags can be written if there is an official syntax.

                  這篇關于Python3 的“函數注釋"有什么好的用途?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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 包)
                    <i id='8uxIc'><tr id='8uxIc'><dt id='8uxIc'><q id='8uxIc'><span id='8uxIc'><b id='8uxIc'><form id='8uxIc'><ins id='8uxIc'></ins><ul id='8uxIc'></ul><sub id='8uxIc'></sub></form><legend id='8uxIc'></legend><bdo id='8uxIc'><pre id='8uxIc'><center id='8uxIc'></center></pre></bdo></b><th id='8uxIc'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='8uxIc'><tfoot id='8uxIc'></tfoot><dl id='8uxIc'><fieldset id='8uxIc'></fieldset></dl></div>

                    • <bdo id='8uxIc'></bdo><ul id='8uxIc'></ul>
                      <tfoot id='8uxIc'></tfoot>
                        <tbody id='8uxIc'></tbody>

                      1. <small id='8uxIc'></small><noframes id='8uxIc'>

                        <legend id='8uxIc'><style id='8uxIc'><dir id='8uxIc'><q id='8uxIc'></q></dir></style></legend>

                            主站蜘蛛池模板: 中文在线观看免费高清 | 国产精品免费在线播放 | 天天澡天天狠天天天做 | 天天天天天干 | 国产无遮挡又黄又爽又色 | 亚洲综合在线视频 | 久久狠狠干 | 亚洲免费黄色 | 国产第一页在线 | 三级网站在线 | 午夜网| 情侣av | 国产伦精品一区二区三区88av | 97人人视频 | 国产成人三级一区二区在线观看一 | 午夜网站在线观看 | 中文字幕在线看片 | 国产精品一区二区三区不卡 | 伊人久久综合 | 午夜精品久久久久久久久久蜜桃 | 亚洲高清视频在线 | 97国产精品 | 日韩精品中文字幕在线观看 | 天天躁日日躁狠狠躁伊人 | 日韩在线成人 | 欧美美女视频 | 在线观看亚洲视频 | 人人爽人人干 | 国产精品无遮挡 | 蜜桃精品视频 | 99这里只有精品视频 | 黄色网址在线播放 | 黄网站免费看 | 日本在线www | 3d动漫精品h区xxxxx区 | 成年人免费在线观看 | 欧美一区二区三区视频 | 日本少妇久久 | 激情视频一区 | 性久久久久久 | 在线成人免费 |