您的位置:首頁技術文章
文章詳情頁

python 函數名之后 有一個箭頭 這是什么作用?

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

問題描述

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

標簽: Python 編程
相關文章:
国产综合久久一区二区三区