![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: pandas.DataFrame()處理雙維度資料,dict跟2D list轉為DataFrame有何差別?如何用index及columns屬性客製化index跟欄位名稱?df.index = [“一”,”二”,”三”,”四”] ; df.columns = 使用.head(n) ; .tail(m) ;取首n列,尾m列; .at[index,欄位名稱] 取單一資料 ; .iat[index,欄位順序] 取單一資料 ; .loc[index,欄位名稱] 取資料 ; .iloc[index,欄位順序];df.iloc[ [0,1],[0,2]])取資料 ; df.iloc[ 0:3,0:2]切片 Python: pandas.DataFrame()處理雙維度資料,dict跟2D list轉為DataFrame有何差別?如何用index及columns屬性客製化index跟欄位名稱?df.index = [“一”,”二”,”三”,”四”] ; df.columns = 使用.head(n) ; .tail(m) ;取首n列,尾m列; .at[index,欄位名稱] 取單一資料 ; .iat[index,欄位順序] 取單一資料 ; .loc[index,欄位名稱] 取資料 ; .iloc[index,欄位順序];df.iloc[ [0,1],[0,2]])取資料 ; df.iloc[ 0:3,0:2]切片](https://i2.wp.com/savingking.com.tw/wp-content/uploads/2022/11/20221111093547_79.png?quality=90&zoom=2&ssl=1&resize=350%2C233)
![Python: pandas.DataFrame串接; pandas.concat( [df1,df2] , axis=1, ignore_index=True) ; .append() 產生一個新的DataFrame; 插入欄 .insert() 改變原DataFrame Python: pandas.DataFrame串接; pandas.concat( [df1,df2] , axis=1, ignore_index=True) ; .append() 產生一個新的DataFrame; 插入欄 .insert() 改變原DataFrame](https://i2.wp.com/savingking.com.tw/wp-content/uploads/2022/11/20221129145451_29.png?quality=90&zoom=2&ssl=1&resize=350%2C233)




![Python: 如何用numpy.ndarray的reshape 將3D array轉為2D array,再轉為pandas.DataFrame? arr.reshape( arr.shape[0] * arr.shape[1] , -1) Python: 如何用numpy.ndarray的reshape 將3D array轉為2D array,再轉為pandas.DataFrame? arr.reshape( arr.shape[0] * arr.shape[1] , -1)](https://i0.wp.com/savingking.com.tw/wp-content/uploads/2023/03/20230320082325_85.png?quality=90&zoom=2&ssl=1&resize=350%2C233)

近期留言