Chinaunix首页 | 论坛 | 博客
  • 博客访问: 303598
  • 博文数量: 47
  • 博客积分: 1190
  • 博客等级: 少尉
  • 技术积分: 523
  • 用 户 组: 普通用户
  • 注册时间: 2008-09-14 20:30
文章分类

全部博文(47)

文章存档

2016年(1)

2012年(46)

我的朋友

分类: Python/Ruby

2012-06-27 10:41:31


在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.

阅读(1109) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~