This is a basic question. Is there a difference in doing
def foo(*args, **kwargs):"""standard function that accepts variable length."""# do somethingfoo(v1...vn, nv1=nv1...nvn=nvn)def foo(arg, kwargs):"""convention, call with tuple and dict."""# do somethingmytuple = (v1, ..vn)
mydict = {nv1=nv1, ...nvn=nvn}
foo(mytuple, mydict)
I could do the same thing with both, except that the later has a weird convention of creating a tuple
and dictionary
. But basically is there a difference? I can solve the same computational problem of handling infinite things because dict
and tuple
can take care of that for me anyway?
Is this more of an idiomatic part of Python i.e a good Syntactic Sugar for things that you do anyway? I.e function
is going to handle this for you!
PS: Not sure of so many downvotes though I agree this is a copy of Why use packed *args/**kwargs instead of passing list/dict? and probably it should be corrected in the duplicate information. And that question has recieved upvotes. So am I being downvotes for not being able to find that?