成人在线亚洲_国产日韩视频一区二区三区_久久久国产精品_99国内精品久久久久久久

您的位置:首頁技術(shù)文章
文章詳情頁

python 函數(shù)名之后 有一個(gè)箭頭 這是什么作用?

瀏覽:105日期:2022-07-01 09:34:33

問題描述

async def fetch(self, url: str, keys: object, repeat: int) -> (int, object): dosomething() return None

在看別人的程序的時(shí)候發(fā)現(xiàn)了這樣的語句,查了不少地方?jīng)]找到關(guān)于“->”的說明。找到比較相似的是箭頭函數(shù),但是樣子都不一樣。

請問這是什么符號?或者我該去哪里查?

問題解答

回答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.

簡單的說-> 就是為了告訴用戶 具體參數(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,對于變量的類型進(jìn)行標(biāo)注,對于pycharm這樣支持的IDE,可以給出更精準(zhǔn)的代碼提示和變量檢查。

具體用法可以看https://docs.python.org/3/lib...

標(biāo)簽: Python 編程
相關(guān)文章: