0 votes
1 view
in Python by (1.6k points)

What are the uses for **kwargs in Python?

I know you can do an objects.filter on a table and pass in a **kwargs argument.  

Can I also do this for specifying time deltas i.e. timedelta(hours = time1)?

How exactly does it work? Is it classes as 'unpacking'? Like p,q=1,2?

1 Answer

0 votes
by (25.1k points)
edited by

**kwargs is short for key worded arguments, they allow you to pass an arbitrary number of key-worded arguments and will be received by the function as an dictionary with keys as the keywords and values as values passed by the user.  e.g.:

def my_function(**kwargs):



The above code will print {'name': 'Anirudh'}

To know more about this you can have a look at the following video tutorial:-

Related questions

0 votes
0 answers
asked Feb 18 by Harsh (1.2k points)
0 votes
1 answer
asked Oct 8, 2019 in Python by Sammy (47.8k points)
0 votes
2 answers
0 votes
2 answers
asked Sep 12, 2019 in Python by Sammy (47.8k points)
Welcome to Intellipaat Community. Get your technical queries answered by top developers !