Skip to main content
3495 votes
28 answers
1.5m views

What do *args and **kwargs mean in these function definitions? def foo(x, y, *args): pass def bar(x, y, **kwargs): pass See What do ** (double star/asterisk) and * (star/asterisk) mean in a ...
Todd's user avatar
  • 36.3k
426 votes
17 answers
587k views

How can I write a function that accepts a variable number of arguments? Is this possible, how?
nunos's user avatar
  • 21.6k
80 votes
11 answers
54k views

I have a float[] and i would like to get a list with the same elements. I could do the ugly thing of adding them one by one but i wanted to use the Arrays.asList method. There is a problem though. ...
Savvas Dalkitsis's user avatar
1057 votes
9 answers
628k views

What do the 3 dots following String in the following method mean? public void myMethod(String... strings) { // method body }
Vikram's user avatar
  • 12.3k
208 votes
8 answers
176k views

I'm afraid of varargs. I don't know what to use them for. Plus, it feels dangerous to let people pass as many arguments as they want. What's an example of a context that would be a good place to ...
Harry Quince's user avatar
  • 2,404
376 votes
6 answers
325k views

I'd like to be able to create a function like: class A { private String extraVar; public String myFormat(String format, Object ... args){ return String.format(format, extraVar, args); } } ...
user362382's user avatar
  • 4,114
365 votes
11 answers
215k views

Say I have a C function which takes a variable number of arguments: How can I call another function which expects a variable number of arguments from inside of it, passing all the arguments that got ...
Vicent Marti's user avatar
  • 7,323
208 votes
12 answers
167k views

Is it possible to send a variable number of arguments to a JavaScript function, from an array? var arr = ['a','b','c'] var func = function() { // debug alert(arguments.length); // ...
Fire Crow's user avatar
  • 7,789
83 votes
11 answers
41k views

I am confused about the spread syntax and rest parameter in ES2015. Can anybody explain the difference between them with proper examples?
Nur Rony's user avatar
  • 8,113
185 votes
12 answers
178k views

So I have 2 functions that both have similar arguments void example(int a, int b, ...); void exampleB(int b, ...); Now example calls exampleB, but how can I pass along the variables in the variable ...
Not Available's user avatar
188 votes
8 answers
110k views

In The Swift Programming Language, it says: Functions can also take a variable number of arguments, collecting them into an array. func sumOf(numbers: Int...) -> Int { ... } When I ...
Ole Begemann's user avatar
468 votes
21 answers
262k views

The arguments object in JavaScript is an odd wart—it acts just like an array in most situations, but it's not actually an array object. Since it's really something else entirely, it doesn't have the ...
Andrew Coleson's user avatar
377 votes
11 answers
216k views

I know this is a basic question, but I couldn't find an answer. Why use it? if you write a function or a method that's using it, when you remove it the code will still work perfectly, 100% as without ...
MasterMastic's user avatar
  • 21.5k
212 votes
13 answers
111k views

I've been trying to get to mock a method with vararg parameters using Mockito: interface A { B b(int x, int y, C... c); } A a = mock(A.class); B b = mock(B.class); when(a.b(anyInt(), anyInt(), ...
qualidafial's user avatar
  • 6,902
105 votes
7 answers
159k views

I have a class that holds an "error" function that will format some text. I want to accept a variable number of arguments and then format them using printf. Example: class MyClass { public: ...
user5722's user avatar
  • 1,314

15 30 50 per page
1
2 3 4 5
36