python 函数参数 *a **kw

时间:2023-03-08 22:07:43
f(name='a')
name
>>> def f(*a,**kw):
print a
for i in kw:
print i >>> f([1,2],n='a',kw={1:5})#调用时,键值对可以name=value,{}的形式提供,两者之一或同时
([1, 2],)
kw
n
class Test():
    def f(self):
        print self#显示self,self的实质对象的地址 >>> o=Test()
>>> o.f()
<__main__.Test instance at 0x013BFD50>
>>> o=Test()
>>> o.f()
<__main__.Test instance at 0x013BFDA0>
>>>