python函數傳遞參數

1.傳遞任意數量的關鍵字實參:符號爲**
def build_porfile(first,last,**user_info):
profile={}
profile[‘first_name’]=first
profile[‘lase_name’]=last
for key,value in user_info.items():
profile[key]=value
return profile

user_info=build_porfile(‘albert’,‘einstein’,location=‘prinecton’,field=‘physics’)

print(user_info)

2.傳遞任意數量的實參:符號爲*
#def sandwitch(*ingredents):
print(“The ingredient of the sandwitch including”)
for ingredent in ingredents:
print(ingredent)
sandwitch(‘cabbage’,‘prock’,‘beef’)
sandwitch(‘mutton’,‘fish’)

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章