python - What is the difference in *args, **kwargs vs calling with tuple and dict? -
this question has answer here:
this basic question. there difference in doing
def foo(*args, **kwargs): """standard function accepts variable length.""" # foo(v1...vn, nv1=nv1...nvn=nvn) def foo(arg, kwargs): """convention, call tuple , dict.""" # mytuple = (v1, ..vn) mydict = {nv1=nv1, ...nvn=nvn} foo(mytuple, mydict)
i same thing both, except later has weird convention of creating tuple
, dictionary
. there difference? can solve same computational problem of handling infinite things because dict
, tuple
can take care of me anyway?
is more of idiomatic part of python i.e syntactic sugar things anyway? i.e function
going handle you!
ps: not sure of many downvotes though agree copy of why use packed *args/**kwargs instead of passing list/dict? , should corrected in duplicate information. , question has recieved upvotes. being downvotes not being able find that?
args
, kwargs
names.
matters here *
, **
.
in second example can call function 2 arguments, against first example can call function infinite arguments.
Comments
Post a Comment