`
dengyin2000
  • 浏览: 1225628 次
  • 性别: Icon_minigender_1
  • 来自: 广州
社区版块
存档分类
最新评论

What does ** and * do for python parameters?

阅读更多
The *args and **kwargs ist a common idiom to allow arbitrary number of arguments to functions as described in the section more on defining functions in the the python documentation.

The *args will give you all funtion parameters a a list:

In [1]: def foo(*args):
   ...:     for a in args:
   ...:         print a
   ...:         
   ...:         

In [2]: foo(1)
1


In [4]: foo(1,2,3)
1
2
3


The **kwargs will give you all keyword arguments except for those corresponding to a formal parameter as a dictionary.

In [5]: def bar(**kwargs):
   ...:     for a in kwargs:
   ...:         print a, kwargs[a]
   ...:         
   ...:         

In [6]: bar(name="one", age=27)
age 27
name one
分享到:
评论

相关推荐

    INTRODUCTION TO PYTHON SCRIPTING FOR MAYA ARTISTS.

    Control structures such as conditionals (if-else statements) and loops (while and for loops) are essential for managing the flow of execution in Python scripts. - **Conditionals:** Conditionals allow...

    护士英文.doc

    9. **What does orientation include and how long does it last?** 培训内容和时长影响新员工的适应速度。 10. **Will I receive full salary during orientation?** 这是经济考虑。 11. **Where are new graduates...

    冀教四年级英语对划线部分提问PPT课件.pptx

    14. **What time do you have lunch?** 同上,询问午餐时间。 15. **How old are you?** 询问年龄。 16. **When is your birthday?** 询问对方的生日日期。 17. **How tall are you?** 询问身高。 18. **What are ...

    超详细美国面签问题汇总.pdf

    10) **What do you do with your work for MS/phd?** 描述你的研究工作或项目,展示你的专业能力和目标。 11) **What is your purpose for the visa?** 明确你申请签证的目的是为了学习,不是为了其他非法目的。 ...

    新人教PEP版六年级上册英语 unit 5 What does he do? 全套课件.pptx

    【新人教PEP版六年级上册英语unit 5 What does he do?】是一堂针对学生职业认知的英语课程,旨在提升学生的英语听说读写能力,特别是与职业相关的词汇和句型的应用。以下是对该课件中涉及的知识点的详细说明: ###...

    英语情景对话购物篇.pdf

    - **What can I do for you?**:这是商店员工常用来询问顾客需求的礼貌用语。 - **Can I help you?**:同上,询问顾客是否需要帮助。 - **Do you find anything you like?**:询问顾客是否找到了心仪的商品。 - ...

    英语口语900句

    - **What does he do?**:询问他人的职业。 - **He's a manager.**:告知他人职业为经理。 - **She must be a model, isn't she?**:猜测对方可能是模特。 - **I really don't know.**:表示不知道对方的职业。 ...

    保研面试常见英文问题.doc

    - **What does your family usually do for the weekend?** 描述家庭的休闲活动,展示家庭的互动和价值观。 - **What do you think about living together with your parents?** 表达你对与父母同住的看法,可以...

    oRTP-0.16.3 软件包下载 2010年7月发布。

    It is available for most unix clones (primilarly Linux and HP-UX), and Microsoft Windows. What are the build prequisites ? ******************************** libc library and header files. How do you...

    复试英语问题.pdf

    - **What does friendship mean to you and what kind of people do you make friend with?** - 解释友谊的意义,并说明自己交友的标准。 - **What is the best university in your opinion?** - 推荐一所心目中的...

    ObsPy – What can it do for data centers and observatories?

    《ObsPy – What can it do for data centers and observatories?》这篇文章探讨了ObsPy作为一种强大的地震数据处理库如何能够有效地支持数据中心和天文台的工作流程。ObsPy不仅简化了地震波形数据的获取与处理,还...

    特殊疑问句讲解及练习.doc

    - **What**: 用于询问事物,例如"What are you doing?"(你在做什么?) - **What time**: 询问具体时间,例如"What time does the train leave?"(火车几点出发?) - **What colour**: 询问颜色,例如"What ...

    Python for Informatics.pdf

    "Python for Informatics" is a comprehensive guide designed to teach readers how to use Python for exploring and managing information. This book, authored by Charles Severance, aims to equip readers ...

    Packt.Python.for.Finance.2nd.Edition.2017

    - **Introduction to Statsmodels**: Statsmodels is a library for statistical modeling and econometric analysis in Python. It includes classes and functions for regression analysis, time series analysis...

    (完整版)Python题库精品练习.pdf

    * 选择题24:在Python中,要利用Python通过数组绘制拟合曲线图,必须要用到的外部库是what? * 选择题25:在Python中,应用软件是为满足用户不同领域、不同问题的应用需求而设计的软件,以下不属于应用软件的是what...

    英文面试常见问题与答案解析归纳.doc

    8. **What kind of salary are you looking for?** 先了解市场行情,给出一个合理的范围,但也可以表示愿意根据公司提供的整体福利进行讨论。 9. **What have you learned from mistakes on the job?** 描述一个...

    购物英语情景对话汇总.doc

    - **What can I do for you?** 这句话通常用于商店或服务场所,询问顾客需要什么帮助。 - **Can I help you?** 同样是向顾客提供服务的常见问句,询问顾客是否需要协助。 2. **选择与购买** - **I want a pair ...

    相当实用的口腔科英语会话.doc

    - **What can I do for you?** - 我能为您做什么? - **What is wrong with you?** - 您哪里不舒服? - **Do you want to see a dentist?** - 您要看牙医吗? - **Which speciality do you want to register ...

    英文原版-Programming Python Programming Guide For Beginners Learn In a Day 2nd Edition

    When you purchase Python: Programming Language for Beginners - Learn In A Day, you'll find out the importance of this language, and how to begin improving your skills! These fun and easy tips ...

Global site tag (gtag.js) - Google Analytics