Sunday, June 8, 2014

star(*) and double star(**) in python

cc from http://stackoverflow.com/questions/36901/what-does-double-star-and-star-do-for-python-parameters.
Mark here:
The *args and **kwargs is a common idiom to allow arbitrary number of arguments to functions.

The *args will give you all function parameters a list:
e.g.
    def foo(*args):
          for a in args:
               print a

The **kwargs will give you all keyword arguments.

  

No comments:

Post a Comment