Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

« Newer Snippets
Older Snippets »
Showing 1-3 of 3 total  RSS 

Variable-length argument list in Python

When you declare an argment to start with '*', it takes the argument list into an array.
def foo(*args):
  print "Number of arguments:", len(args)
  print "Arguments are: ", args

Variable-length argument list in PHP

See the document for
func_num_args(), func_get_arg(), and func_get_args().
function foo()
{
   $numargs = func_num_args();
   echo "Number of arguments: $numargs<br />\n";
   if ($numargs >= 2) {
       echo "Second argument is: " . func_get_arg(1) . "<br />\n";
   }
   $arg_list = func_get_args();
   for ($i = 0; $i < $numargs; $i++) {
       echo "Argument $i is: " . $arg_list[$i] . "<br />\n";
   }
}

foo(1, 2, 3);

Passing argument list and keyword list

>>> def blit(*args, **kw):
...   canvas.blit(*args, **kw)
« Newer Snippets
Older Snippets »
Showing 1-3 of 3 total  RSS