2006年06月01日 星期四 09:47
On 5/31/06, 帆 杨 <decca.yang at yahoo.com.cn> wrote: > > 看到这样的用法 > class MyClass: > __init__(self,**args): > #init code > ... ... > myClass = MyClass(key='value') > 这里将key='value'传给**args后,args是一个dictionary,{'key':'value'} > 这里的"*"具体是什么作用呢?和c里面的"*"有没有什么联系呢? > 还请个位指点一二。 > > 怎么不先查查python自带的文档呢? Language Reference的5.3.4和7.5里都有说啊: If any keyword argument does not correspond to a formal parameter name, a TypeError exception is raised, unless a formal parameter using the syntax " **identifier" is present; in this case, that formal parameter receives a dictionary containing the excess keyword arguments (using the keywords as keys and the argument values as corresponding values), or a (new) empty dictionary if there were no excess keyword arguments. -- Best Regards, Leo Jay -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20060601/e6ecb646/attachment.htm
Zeuux © 2025
京ICP备05028076号