*args和**kwargs的意义

1134阅读 0评论2012-06-27 wdove
分类:Python/Ruby


在override __init__()时,经常会有*args和**kwargs,*args代表接受任意实参, **kwargs代表接受任意keyword参数。

Putting *args and/or **kwargs as the last items in your function definition’s argument list allows that function to accept an arbitrary number of anonymous and/or keyword arguments.

It’s probably more commonly used in object-oriented programming, when you’re overriding a function, and want to call the original function with whatever arguments the user passes in.

You don’t actually have to call them args and kwargs, that’s just a convention. It’s the * and ** that do the magic.

上一篇:Pass parameter to form field | 在form field初始化时如何传参给它
下一篇:提交表单时出现: "CSRF verification failed. Request aborted."