這是函數(shù)注解,Python 3.x引入,它的特點(diǎn)有
蓬江ssl適用于網(wǎng)站、小程序/APP、API接口等需要進(jìn)行數(shù)據(jù)傳輸應(yīng)用場景,ssl證書未來市場廣闊!成為成都創(chuàng)新互聯(lián)公司的ssl證書銷售渠道,可以享受市場價(jià)格4-6折優(yōu)惠!如果有意向歡迎電話聯(lián)系或者加微信:13518219792(備注:SSL證書合作)期待與您的合作!
對函數(shù)的參數(shù)進(jìn)行類型注解,以冒號標(biāo)記
對函數(shù)的返回值進(jìn)行類型注解,以箭頭標(biāo)記
只對函數(shù)參數(shù)或返回值做一個(gè)輔助的說明,并不對函數(shù)參數(shù)或返回值進(jìn)行類型檢查
提供給第三方工具,做代碼分析,發(fā)現(xiàn)隱藏bug
函數(shù)注解的信息,保存在__annotations__屬性中
注解本身是一個(gè)字典類型的數(shù)據(jù)
你的程序我?guī)湍阃晟屏?函數(shù)注解部分的解釋見注釋),你看看吧
from?typing?import?List
def?f(a)?-?List[dict]:?#函數(shù)注解,返回一個(gè)字典列表,但是它不對返回值類型進(jìn)行檢查
print(a)??#打印字典
return?[a]?#返回字典列表
print(f.__annotations__)?#打印函數(shù)注解
l={'Name':?'Zara','Age':17}?#把字典傳入函數(shù)
print(f(l))?#打印函數(shù)返回值
源代碼(注意源代碼的縮進(jìn))
你用的graphics模塊?這不是內(nèi)置的,雖然它是調(diào)用內(nèi)置的Tkinter畫圖。
option可以是"first","last","both"或"none"。見graphics.py:
def setArrow(self, option):
if not option in ["first","last","both","none"]:
raise GraphicsError(BAD_OPTION)
self._reconfig("arrow", option)
細(xì)節(jié)要查Tk文檔:
6.6. The canvas line object
In general, a line can consist of any number of segments connected end to end, and each segment can be straight or curved. To create a canvas line object on a canvas C, use:
id = C.create_line ( x0, y0, x1, y1, ..., xn, yn, option, ... )
The line goes through the series of points
(x0,
y0),
(x1,
y1),
…
(xn,
yn).
Options include:
arrow The default is for the line to have no arrowheads. Use
arrow=FIRST to get an arrowhead at the(x0,y0)end of the line. Use
arrow=LAST to get an arrowhead at the far end. Use
arrow=BOTH for arrowheads at both ends.
Python 函數(shù)參數(shù)有冒號 -?聲明
type hint, 即類型提示 。
官方網(wǎng)站:
def add(a,b) - int:
return a+b
函數(shù)可以不加-表示動態(tài)定義。a b?數(shù)據(jù)類型不一定為int,也可以為float
加-表示靜態(tài)定義。a b?數(shù)據(jù)類型為int
文章名稱:python箭頭函數(shù) 實(shí)現(xiàn)箭頭函數(shù)
URL網(wǎng)址:http://aaarwkj.com/article8/hhhjop.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供手機(jī)網(wǎng)站建設(shè)、外貿(mào)網(wǎng)站建設(shè)、關(guān)鍵詞優(yōu)化、建站公司、網(wǎng)站設(shè)計(jì)公司、網(wǎng)站策劃
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)