In JavaScript each function has a special arguments predefined objects which holds information about arguments passed to the function call, e.g.
function test() {
var args = Array.prototype.slice.call(arguments);
console.log(args);
}
arguments can be easily dumped to a standard array:
test()
// []
test(1,2,3)
// [1, 2, 3]
test("hello", 123, {}, [], function(){})
// ["hello", 123, Object, Array[0], function]
I know that in Python I can use standard arguments, positional arguments and keyword arguments (just like defined here) to manage dynamic parameter number - but is there anything similar to arguments object in Python?
*argsand**kwargs, but those only give you "extra" arguments, not all arguments. There is somewhat less need forargumentsin Python because (unlike Javascript) it's not possible to call a function with the wrong number of arguments (i.e., if a function requires two arguments, calling it with just one will give an error). What do you want to accomplish that makes you want to use something likearguments?arguments, e.g. you can make a standardmemoizefunction with one parameter (which is a function to be memoized) which will return closured memoized function. This is done usingarguments, as you can see here (see chapter automatic memoization).arguments, as I can see. Thanks.