Python入门09——函数的参数
在Python中,函数的参数主要可以分为以下三种类型: 1、可变参数 可变参数必须放在固定参数之后。 >>> def fun(a,b,*args): print(a,b,args) >>> fun(1,2,3,4,5) 1 2 (3, 4, 5) 2、关键字参数 必须成对传值:key = value >>> d = dict(one=1,two=2,three=3,four=4) >>> def fun(**kwargs): print(kwargs) >>> fun(**d) {'one': 1, 'two': 2, 'three': 3, 'four': 4} >>> fun(
下载地址
用户评论