`
dengyin2000
  • 浏览: 1209175 次
  • 性别: 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
分享到:
评论

相关推荐

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

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

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

    英文原版-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 ...

    Pro Python电子版

    Who this book is for This book is for intermediate to advanced Python programmers who are looking to understand how and why Python works the way it does and how they can take their code to the next ...

    Hands-On Blockchain for Python Developers

    Hands-On Blockchain for Python Developers starts by demonstrating how blockchain technology and cryptocurrency hashing works. You will understand the fundamentals and benefits of smart contracts such ...

    Python for the Busy Java Developer

    Hit the ground running and gain a fast-paced overview of what the Python language is all about, the syntax that it uses and the ecosystem of libraries and tools that surround the language. This ...

    Black Hat PytHon Python Programming for Hackers and Pentesters

    To start, I lay down some networking fundamentals in Chapter 2 and slowly work our way through raw sockets in Chapter 3 and using Scapy in Chapter 4 for some more interesting network tooling....

    What Is ChatGPT Doing ... and Why Does It Work.pdf

    ChatGPT研究资料,What Is ChatGPT Doing ... and Why Does It Work (Stephen Wolfram) (Z-Library)

    Python Algorithms

    Python Algorithms explains the Python approach to algorithm analysis and design. Written by Magnus Lie Hetland, author of Beginning Python, this book is sharply focused on classical algorithms, but it...

    MySQL for Python 2010.pdf

    Automate the creation and removal of databases and tables using MySQL for Python Use the MySQL for Python library to automate user creation and to administer access controls Log user activity with ...

    Raspberry Pi for Python Programmers Cookbook (Second Edition)

    Raspberry Pi for Python Programmers Cookbook (Second Edition)-P2P English | 2016 | 450 pages Raspberry Pi cookbook for Python Programmers is a practical guide for getting the most out of this little ...

    Python for Scientists

    The title of this book is “Python for Scientists”, but what does that mean? The dictionary defines “Python” as either (a) a non-venomous snake from Asia or Saharan Africa or (b) a computer ...

    python pdf 電子書

    What Can I Do with Python? 9 Systems Programming 9 GUIs 9 Internet Scripting 10 Component Integration 10 Database Programming 11 Rapid Prototyping 11 Numeric and Scientific Programming 11 Gaming, ...

    Pro Python

    Who this book is for This book is for intermediate to advanced Python programmers who are looking to understand how and why Python works the way it does and how they can take their code to the next ...

    Python for the Busy Java Developer(pdf电子原版2017版

    Hit the ground running and gain a fast-paced overview of what the Python language is all about, the syntax that it uses and the ecosystem of libraries and tools that surround the language. This ...

    Python for Data Mining Quick Syntax Reference

    The second part covers Python’s most important data mining packages: NumPy and SciPy for mathematical functions and random data generation, pandas for dataframe management and data import, ...

    Python Continuous Integration and Delivery

    Gain the techniques and tools that enable a smooth and efficient software development process in this quick and practical guide on Python continuous integration (CI) and continuous delivery (CD)....

    What Can Style Transfer and Paintings Do for Model Robustness

    What Can Style Transfer and Paintings Do for Model Robustness

    What Is ChatGPT Doing ... and Why Does It Work(2023)

    没有人预料到这一点——甚至包括它的创造者:ChatGPT作为一种能够以令人信服的人类水平进行写作的AI已经出现在舞台上。但是它真正的工作原理是什么?其“AI大脑”内部发生了什么?在这本短篇书籍中,杰出科学家和...

Global site tag (gtag.js) - Google Analytics