1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
| def position_param(name,age,isMarry): print(f"姓名:{name}年龄{age}婚后{isMarry}")
position_param("jack",30,True) def keyword_param(name,age,isMarry): print(f"姓名:{name}年龄{age}婚后{isMarry}")
keyword_param(name="andi",age=26,isMarry=False) keyword_param(isMarry=True,age=35,name="doci")
keyword_param("mark",isMarry=False,age=28) def default_param(name,age,isMarry=False): print(f"姓名{name}年龄{age}婚后{isMarry}")
default_param("petre",18) default_param("jame",age=32,isMarry=True)
def sum(*args): print(f"参数:{args}类型{type(args)}") sum = 0 for n in args: sum += n return sum
result = sum(1,2,3,4,5) print(f"1~5的累加和{result}") result = sum(1,2,3,4,5,6,7,8,9,10) print(f"1~10的累加和{result}")
def staff_info(**kwargs): print(f"参数:{kwargs}类型:{type(kwargs)}")
staff_info(name="ldis",age=12) staff_info(name="dafsdv",age=12,isMarry = False)
|