不定长函数

 1 # 获取一个学生信息
 2 # name  age  idNum
 3 # weight  height
 4 
 5 def getStuInfo(name, age, idNum, **kwargs):
 6     print(name, age, idNum)
 7     if kwargs.get("weight") != None:
 8         print(kwargs["weight"])
 9     if kwargs.get("height") != None:
10         print(kwargs["height"])
11 
12 
13 
14 getStuInfo("lily", 12, 2019)
15 getStuInfo("lily", 12, 2019, weight=51.9)
16 getStuInfo("lily", 12, 2019, height=178)
17 getStuInfo("lily", 12, 2019, height=178, weight=52.8)

 

posted @ 2019-07-29 19:16  巨菜的小鸟  阅读(176)  评论(0编辑  收藏  举报