1、那個是函數(shù)定義中,返回值的類型說明。沒有具體作用,相當于注釋。
創(chuàng)新互聯(lián)主營循化網(wǎng)站建設的網(wǎng)絡公司,主營網(wǎng)站建設方案,成都app軟件開發(fā),循化h5小程序設計搭建,循化網(wǎng)站營銷推廣歡迎循化等地區(qū)企業(yè)咨詢
2、沒有為什么,是python的語法。字典就是可以:字典["key"]=value這樣來添加鍵值對。
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
這是函數(shù)注解,Python 3.x引入,它的特點有
對函數(shù)的參數(shù)進行類型注解,以冒號標記
對函數(shù)的返回值進行類型注解,以箭頭標記
只對函數(shù)參數(shù)或返回值做一個輔助的說明,并不對函數(shù)參數(shù)或返回值進行類型檢查
提供給第三方工具,做代碼分析,發(fā)現(xiàn)隱藏bug
函數(shù)注解的信息,保存在__annotations__屬性中
注解本身是一個字典類型的數(shù)據(jù)
你的程序我?guī)湍阃晟屏?函數(shù)注解部分的解釋見注釋),你看看吧
from?typing?import?List
def?f(a)?-?List[dict]:?#函數(shù)注解,返回一個字典列表,但是它不對返回值類型進行檢查
print(a)??#打印字典
return?[a]?#返回字典列表
print(f.__annotations__)?#打印函數(shù)注解
l={'Name':?'Zara','Age':17}?#把字典傳入函數(shù)
print(f(l))?#打印函數(shù)返回值
源代碼(注意源代碼的縮進)
你用的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)
細節(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ù)箭頭 python 箭頭函數(shù)
本文網(wǎng)址:http://chinadenli.net/article12/dooosdc.html
成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站導航、軟件開發(fā)、定制網(wǎng)站、服務器托管、網(wǎng)頁設計公司、微信小程序
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)