python 函數(shù)名之后 有一個(gè)箭頭 這是什么作用?
問題描述
async def fetch(self, url: str, keys: object, repeat: int) -> (int, object): dosomething() return None
在看別人的程序的時(shí)候發(fā)現(xiàn)了這樣的語句,查了不少地方?jīng)]找到關(guān)于“->”的說明。找到比較相似的是箭頭函數(shù),但是樣子都不一樣。
請(qǐng)問這是什么符號(hào)?或者我該去哪里查?
問題解答
回答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.
簡(jiǎn)單的說-> 就是為了告訴用戶 具體參數(shù)和參數(shù)的類型。
詳細(xì)的可以看:PEP3107https://www.python.org/dev/pe...
回答3:只是提示該函數(shù) 輸入?yún)?shù) 和 返回值 的數(shù)據(jù)類型
方便程序員閱讀代碼的。
回答4:http://python3-cookbook.readt...
python cookbook里面有詳細(xì)描述,建議有空多看看這本書,還是很有幫助的。
回答5:這個(gè)是。。。提示返回值類型的?
回答6:這個(gè)是從python3.5開始就正式納入的type hint,對(duì)于變量的類型進(jìn)行標(biāo)注,對(duì)于pycharm這樣支持的IDE,可以給出更精準(zhǔn)的代碼提示和變量檢查。
具體用法可以看https://docs.python.org/3/lib...
相關(guān)文章:
1. javascript - immutable配合react提升性能?2. javascript - sublime快鍵鍵問題3. 如何解決Centos下Docker服務(wù)啟動(dòng)無響應(yīng),且輸入docker命令無響應(yīng)?4. javascript - 移動(dòng)端上不能實(shí)現(xiàn)拖拽布局嗎?5. vue.js - Vue 如何像Angular.js watch 一樣監(jiān)聽數(shù)據(jù)變化6. 實(shí)現(xiàn)bing搜索工具urlAPI提交7. index.php錯(cuò)誤,求指點(diǎn)8. thinkPHP5中獲取數(shù)據(jù)庫(kù)數(shù)據(jù)后默認(rèn)選中下拉框的值,傳遞到后臺(tái)消失不見。有圖有代碼,希望有人幫忙9. angular.js - 單頁(yè)應(yīng)用(ng/vue)該如何監(jiān)聽用戶離開當(dāng)前頁(yè)面(或者路由)?10. javascript - ios返回不執(zhí)行js怎么解決?

網(wǎng)公網(wǎng)安備