Difference between *args and **kwargs

+1 Usama tariq · November 27, 2015
Can anyone please tell me the difference between *args and **kwargs.I know *args is used when we don't know how much arguments will the user pass.Whats **kwargs used for ?

Post a Reply

Replies

Oldest  Newest  Rating
0 Halcyon Abraham Ramirez · November 29, 2015
*args is variable position arguments.
**kwargs variable keyword arguments.

and "args" and "kwargs" are not keywords, just variable names.

so *somename, **somename2 is completely valid


try this


def testArgs(*args):
   return args

def testKwargs(**kwargs):
   return kwargs

print(testArgs("hello", "hi", "hey"))
print(testKwargs(a = " hello", b = "hmm", c="random"))
  • 1

Python

106,995 followers
About

This section is all about snakes! Just kidding.

Links
Moderators
Bucky Roberts Administrator