Linked Questions

1596 votes
11 answers
986k views

So I have difficulty with the concept of *args and **kwargs. So far I have learned that: *args = list of arguments - as positional arguments **kwargs = dictionary - whose keys become separate keyword ...
863 votes
13 answers
749k views

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)? ...
Federer's user avatar
  • 35.1k
404 votes
5 answers
324k views

Does * have a special meaning in Python as it does in C? I saw a function like this in the Python Cookbook: def get(self, *a, **kw) Would you please explain it to me or point out where I can find an ...
Martin08's user avatar
  • 21.6k
300 votes
5 answers
202k views

What exactly do *args and **kwargs mean? According to the Python documentation, from what it seems, it passes in a tuple of arguments. def foo(hello, *args): print(hello) for each in args: ...
UberJumper's user avatar
  • 21.4k
144 votes
3 answers
135k views

What do the * and ** mean in this code? def functionA(self, *a, **kw): # code here
hqt's user avatar
  • 30.4k
86 votes
1 answer
38k views

I am not able understand where does these type of functions are used and how differently these arguments work from the normal arguments. I have encountered them many time but never got chance to ...
Shiv Deepak's user avatar
  • 3,136
25 votes
2 answers
62k views

Simple program: storyFormat = """ Once upon a time, deep in an ancient jungle, there lived a {animal}. This {animal} liked to eat {food}, but the ...
DNB5brims's user avatar
  • 30.8k
19 votes
1 answer
11k views

While going through the source code, I noticed the following syntax being used in the asyncio library: @coroutine def sleep(delay, result=None, *, loop=None): """Coroutine that completes after a ...
6harat's user avatar
  • 632
7 votes
2 answers
28k views

How would I pass an unknown number of parameters into a function? I have a function defined in the following way def func(x, *p): # do something with variable number of parameters (*p) pass I'...
11 votes
2 answers
10k views

I am using Python trying to figure out a key word and I see the word, "kwargs", which I know is some kind of argument in the called function but I can not find what it means or stands for anywhere. ...
boB's user avatar
  • 111
8 votes
1 answer
3k views

Possible Duplicate: What does ** (double star) and * (star) do for python parameters? I am reading some code that been generated by ZSI for python. There is a line like this def verifyVehicle(...
ACZINT's user avatar
  • 91
6 votes
4 answers
4k views

From reading this example and from my slim knowledge of Python it must be a shortcut for converting an array to a dictionary or something? class hello: def GET(self, name): return render....
Ryan Detzel's user avatar
  • 5,619
3 votes
2 answers
10k views

I'm passing a lot data around; specifically, I'm trying to pass the output of a function into a class and the output contains a tuple with three variables. I can't directly pass the output from my ...
O.rka's user avatar
  • 31.1k
9 votes
4 answers
4k views

data = pd.read_csv("customers.csv") print("Wholesale customers dataset has {} samples with {} features each." .format(*data.shape)) After this, I got the dimension numbers of the data. But I am ...
1 vote
3 answers
9k views

I was doing a Hackerrank python problem the task was to print 123...N (where N is the input) without using any string function. Someone commented a solution which is: ...

15 30 50 per page
1
2 3 4 5
...
41