0
def Foo( *args, **kargs ):

I know that **kargs can take multiple arguments. But, what's the dealt about function method has both *args and **kargs? How to use it in real world?

Can anyone give me an example? Thank you!

BufBills
  • 8,005
  • 12
  • 48
  • 90
  • It doesn't matter but we often use `**kwargs` to denote keyword arguments. – Malik Brahimi Mar 19 '15 at 20:53
  • And by the way, I have no idea what you mean by real world. Programming is an art. You solve problems as you deem necessary. Use, don't use it. It's up to you what you want to do and how you want to do it. – Malik Brahimi Mar 19 '15 at 20:54
  • possible duplicate of [\*args and \*\*kwargs?](http://stackoverflow.com/questions/3394835/args-and-kwargs) – ashwinjv Mar 19 '15 at 20:58
  • take a look at [izip_longest](https://docs.python.org/2/library/itertools.html#itertools.izip_longest) and [product](https://docs.python.org/2/library/itertools.html#itertools.product) – Matt Mar 19 '15 at 21:02

1 Answers1

5

Read the documentation: https://docs.python.org/2/tutorial/controlflow.html#keyword-arguments

*args has no variable assigned to it. Instead you end up with args being a list of values that were placed in the function.

**kwargs has a variable(key word) associated with it.

The order of these values don't matter. Leaving them out wont break the function unless it was created to break if specific keywords were left out. They are typically optional. The python docs explain it very well.

Carter
  • 332
  • 3
  • 13