python 函數名之后 有一個箭頭 這是什么作用?
問題描述
async def fetch(self, url: str, keys: object, repeat: int) -> (int, object): dosomething() return None
在看別人的程序的時候發現了這樣的語句,查了不少地方沒找到關于“->”的說明。找到比較相似的是箭頭函數,但是樣子都不一樣。
請問這是什么符號?或者我該去哪里查?
問題解答
回答1:Function annotations ?'Python 3 provides syntax to attach metadata to the parameters of a function declarationand its return value.'
回答2:Stackoverflow有了。What does -> mean in Python function definitions?
Python 3 extends the feature by allowing you to attach metadata to functions describing their parameters and return values.
簡單的說-> 就是為了告訴用戶 具體參數和參數的類型。
詳細的可以看:PEP3107https://www.python.org/dev/pe...
回答3:只是提示該函數 輸入參數 和 返回值 的數據類型
方便程序員閱讀代碼的。
回答4:http://python3-cookbook.readt...
python cookbook里面有詳細描述,建議有空多看看這本書,還是很有幫助的。
回答5:這個是。。。提示返回值類型的?
回答6:這個是從python3.5開始就正式納入的type hint,對于變量的類型進行標注,對于pycharm這樣支持的IDE,可以給出更精準的代碼提示和變量檢查。
具體用法可以看https://docs.python.org/3/lib...
相關文章:
1. javascript - 最終生成的jsBundle文件壓縮問題2. android - 啟動模擬器的,報“Could not automatically detect an ADB binary……”,要怎么解決?3. python - TypeError: tryMsgcode() takes exactly 2 arguments (0 given)4. 關于Java引用傳遞的一個困惑?5. 如何分別在Windows下用Winform項模板+C#,在MacOSX下用Cocos Application項目模板+Objective-C實現一個制作游戲的空的黑窗口?6. angular.js - angularjs的自定義過濾器如何給文字加顏色?7. 關于docker下的nginx壓力測試8. android clickablespan獲取選中內容9. docker安裝后出現Cannot connect to the Docker daemon.10. javascript - 關于json中獲取多個key-value對中多層嵌套key的name
