![Python, typing: 函數庫規格標註; def addTest(x:float, y:float) -> float: List[資料型態] Set[資料型態] Tuple[資料型態] Dict[str,value的資料型態] Union[資料型態1, 資料型態2] ,函式若有多個輸出值,其實是輸出一個tuple - 儲蓄保險王](https://savingking.com.tw/wp-content/uploads/2022/09/20220907154601_86.png)
def addTest(x:float,y:float)->float:
return x+y
x = “p”
y = “q”
print(addTest(x,y))
#typing沒有強制力
#硬要輸入字串
x = 1.2
y = 2.8
print(addTest(x,y))
![Python, typing: 函數庫規格標註; def addTest(x:float, y:float) -> float: List[資料型態] Set[資料型態] Tuple[資料型態] Dict[str,value的資料型態] Union[資料型態1, 資料型態2] ,函式若有多個輸出值,其實是輸出一個tuple - 儲蓄保險王](https://savingking.com.tw/wp-content/uploads/2022/09/20220907154335_4.png)
dict用{key : value} 建構
Dict[str , value的資料型態]
中間卻是使用, 非:
![Python, typing: 函數庫規格標註; def addTest(x:float, y:float) -> float: List[資料型態] Set[資料型態] Tuple[資料型態] Dict[str,value的資料型態] Union[資料型態1, 資料型態2] ,函式若有多個輸出值,其實是輸出一個tuple - 儲蓄保險王](https://savingking.com.tw/wp-content/uploads/2022/09/20220907155806_79.png)
![Python, typing: 函數庫規格標註; def addTest(x:float, y:float) -> float: List[資料型態] Set[資料型態] Tuple[資料型態] Dict[str,value的資料型態] Union[資料型態1, 資料型態2] ,函式若有多個輸出值,其實是輸出一個tuple - 儲蓄保險王](https://savingking.com.tw/wp-content/uploads/2022/09/20220907160022_81.png)
import typing
cmd:typing.Dict[str,bytes] = {
“ConfigBig” : b’\x00C\x00o\x00n\x00f\x00i\x00g’,
“ControlBig” : b’\x00C\x00o\x00n\x00t\x00r\x00o\x00l’,
“ReControlBig”: b’\x00R\x00e\x00C\x00o\x00n\x00t\x00r\x00o\x00l’,
“StopBig” : b’\x00S\x00t\x00o\x00p’
}
#command使用大端,用ctrl_socket.send()傳送
![Python, typing: 函數庫規格標註; def addTest(x:float, y:float) -> float: List[資料型態] Set[資料型態] Tuple[資料型態] Dict[str,value的資料型態] Union[資料型態1, 資料型態2] ,函式若有多個輸出值,其實是輸出一個tuple - 儲蓄保險王](https://savingking.com.tw/wp-content/uploads/2022/09/20221104111604_81.png)
如果自定義函式輸出
兩個以上的結果
其實是輸出一個tuple
若兩個結果的資料型態不同
可以用以下的方法typing
from typing import Tuple
def gainParam2(Gain_P:list,DO:int=0)-> Tuple[bytes,list]:
#DO:int=0 ,先typing,再預設值
#有預設值的參數需要放最後面
#DO後面不能再有其他
#無預設值的參數
函式若有多個輸出值,
其實是輸出一個tuple:
![Python, typing: 函數庫規格標註; def addTest(x:float, y:float) -> float: List[資料型態] Set[資料型態] Tuple[資料型態] Dict[str,value的資料型態] Union[資料型態1, 資料型態2] ,函式若有多個輸出值,其實是輸出一個tuple - 儲蓄保險王](https://savingking.com.tw/wp-content/uploads/2022/09/20221108083548_82.png)
這樣也可以Typing:
![Python, typing: 函數庫規格標註; def addTest(x:float, y:float) -> float: List[資料型態] Set[資料型態] Tuple[資料型態] Dict[str,value的資料型態] Union[資料型態1, 資料型態2] ,函式若有多個輸出值,其實是輸出一個tuple - 儲蓄保險王](https://savingking.com.tw/wp-content/uploads/2022/09/20230508203853_80.png)
或者:
![Python, typing: 函數庫規格標註; def addTest(x:float, y:float) -> float: List[資料型態] Set[資料型態] Tuple[資料型態] Dict[str,value的資料型態] Union[資料型態1, 資料型態2] ,函式若有多個輸出值,其實是輸出一個tuple - 儲蓄保險王](https://savingking.com.tw/wp-content/uploads/2022/09/20230508204356_44.png)
推薦hahow線上學習python: https://igrape.net/30afN




![Python 讀取 DOCX 圖片關聯:qn+find/findall 與 XPath 的實戰對照 from lxml import etree ; from docx.oxml.ns import qn; lxml.etree._Element.findall( f”.//{ qn(‘a:blip’) }” ) ; .get( qn(“r:embed”) ) #獲取 屬性名 ‘r:embed’ 的 屬性值(如: ‘rId4’) ; lxml.etree._Element.xpath( “//a:blip/@r:embed”, namespaces = NS) #/@r:embed = 獲取 屬性名 ‘r:embed’ 的 屬性值(如: ‘rId4’),使用.findall() 要先.findall()獲取List[_Element],再迴圈_Element.get()獲取屬性值, .xpath() 第一個參數path 使用”//a:blip/@r:embed” ,可直接獲取屬性值(List[str]如: [‘rId4’, ‘rId5’]) ; 如何對docx真實移除圖片瘦身? Python 讀取 DOCX 圖片關聯:qn+find/findall 與 XPath 的實戰對照 from lxml import etree ; from docx.oxml.ns import qn; lxml.etree._Element.findall( f”.//{ qn(‘a:blip’) }” ) ; .get( qn(“r:embed”) ) #獲取 屬性名 ‘r:embed’ 的 屬性值(如: ‘rId4’) ; lxml.etree._Element.xpath( “//a:blip/@r:embed”, namespaces = NS) #/@r:embed = 獲取 屬性名 ‘r:embed’ 的 屬性值(如: ‘rId4’),使用.findall() 要先.findall()獲取List[_Element],再迴圈_Element.get()獲取屬性值, .xpath() 第一個參數path 使用”//a:blip/@r:embed” ,可直接獲取屬性值(List[str]如: [‘rId4’, ‘rId5’]) ; 如何對docx真實移除圖片瘦身?](https://i0.wp.com/savingking.com.tw/wp-content/uploads/2025/11/20251119130848_0_3fbf6b.png?quality=90&zoom=2&ssl=1&resize=350%2C233)



![Python 進階技巧:海象運算子 (Walrus Operator) 實戰教學 [w_clean for w in words if (w_clean:=w.lower().strip()) and w_clean not in STOPWORDS] Python 進階技巧:海象運算子 (Walrus Operator) 實戰教學 [w_clean for w in words if (w_clean:=w.lower().strip()) and w_clean not in STOPWORDS]](https://i1.wp.com/savingking.com.tw/wp-content/uploads/2026/02/20260210083748_0_a7d9bf.png?quality=90&zoom=2&ssl=1&resize=350%2C233)

近期留言