pbootcms网站模板|日韩1区2区|织梦模板||网站源码|日韩1区2区|jquery建站特效-html5模板网

<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="h22dvt3" 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="wwzfxk7" 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="ccqloec" 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>

                            主站蜘蛛池模板: 吹田功率计-长创耐压测试仪-深圳市新朗普电子科技有限公司 | 碳纤维复合材料制品生产定制工厂订制厂家-凯夫拉凯芙拉碳纤维手机壳套-碳纤维雪茄盒外壳套-深圳市润大世纪新材料科技有限公司 | 集装箱展厅-住人集装箱住宿|建筑|房屋|集装箱售楼处-山东锐嘉科技工程有限公司 | 三效蒸发器_多效蒸发器价格_四效三效蒸发器厂家-青岛康景辉 | 电梯装饰-北京万达中意电梯装饰有限公司 | 热缩管切管机-超声波切带机-织带切带机-无纺布切布机-深圳市宸兴业科技有限公司 | 超声波焊接机_超音波熔接机_超声波塑焊机十大品牌_塑料超声波焊接设备厂家 | 北京浩云律师事务所-企业法律顾问_破产清算等公司法律服务 | 安平县鑫川金属丝网制品有限公司,声屏障,高速声屏障,百叶孔声屏障,大弧形声屏障,凹凸穿孔声屏障,铁路声屏障,顶部弧形声屏障,玻璃钢吸音板 | 517瓜水果特产网|一个专注特产好物的网站 | 袋式过滤器,自清洗过滤器,保安过滤器,篮式过滤器,气体过滤器,全自动过滤器,反冲洗过滤器,管道过滤器,无锡驰业环保科技有限公司 | 天津蒸汽/热水锅炉-电锅炉安装维修直销厂家-天津鑫淼暖通设备有限公司 | 乐之康护 - 专业护工服务平台,提供医院陪护-居家照护-居家康复 | 石家庄小程序开发_小程序开发公司_APP开发_网站制作-石家庄乘航网络科技有限公司 | 电脑知识|软件|系统|数据库|服务器|编程开发|网络运营|知识问答|技术教程文章 - 好吧啦网 | 真空干燥烘箱_鼓风干燥箱 _高低温恒温恒湿试验箱_光照二氧化碳恒温培养箱-上海航佩仪器 | ?水马注水围挡_塑料注水围挡_防撞桶-常州瑞轩水马注水围挡有限公司 | 常州减速机_减速机厂家_常州市减速机厂有限公司 | 304不锈钢无缝管_不锈钢管厂家 - 隆达钢业集团有限公司 | 焊锡丝|焊锡条|无铅锡条|无铅锡丝|无铅焊锡线|低温锡膏-深圳市川崎锡业科技有限公司 | 超声波焊接机,振动摩擦焊接机,激光塑料焊接机,超声波焊接模具工装-德召尼克(常州)焊接科技有限公司 | 广州各区危化证办理_危险化学品经营许可证代办 | 吉祥新世纪铝塑板_生产铝塑板厂家_铝塑板生产厂家_临沂市兴达铝塑装饰材料有限公司 | 森旺-A级防火板_石英纤维板_不燃抗菌板装饰板_医疗板 | 广州冷却塔维修厂家_冷却塔修理_凉水塔风机电机填料抢修-广东康明节能空调有限公司 | 武汉画册印刷厂家-企业画册印刷-画册设计印刷制作-宣传画册印刷公司 - 武汉泽雅印刷厂 | 重庆网站建设,重庆网站设计,重庆网站制作,重庆seo,重庆做网站,重庆seo,重庆公众号运营,重庆小程序开发 | 空压机网_《压缩机》杂志 | 开平机_纵剪机厂家_开平机生产厂家|诚信互赢-泰安瑞烨精工机械制造有限公司 | 暖气片十大品牌厂家_铜铝复合暖气片厂家_暖气片什么牌子好_欣鑫达散热器 | 劳动法网-专业的劳动法和劳动争议仲裁服务网 | 广东高华家具-公寓床|学生宿舍双层铁床厂家【质保十年】 | 涡轮流量计_LWGY智能气体液体电池供电计量表-金湖凯铭仪表有限公司 | 在线浊度仪_悬浮物污泥浓度计_超声波泥位计_污泥界面仪_泥水界面仪-无锡蓝拓仪表科技有限公司 | 实木家具_实木家具定制_全屋定制_美式家具_圣蒂斯堡官网 | 箱式破碎机_移动方箱式破碎机/价格/厂家_【华盛铭重工】 | 「银杏树」银杏树行情价格_银杏树种植_山东程锦园林 | 圣才学习网-考研考证学习平台,提供万种考研考证电子书、题库、视频课程等考试资料 | 高空重型升降平台_高空液压举升平台_高空作业平台_移动式升降机-河南华鹰机械设备有限公司 | 聚丙烯酰胺_阴离子_阳离子「用量少」巩义亿腾厂家直销,售后无忧 聚合甘油__盐城市飞龙油脂有限公司 | CCC验厂-家用电器|服务器CCC认证咨询-奥测世纪 |