One: Cause
(0) Indeterminate length parameter, also called variable parameter, is not sure how many parameters need to be passed before calling function again
(1) Variable length parameters in Java with string ... args/int ... Args, such as three points to represent; Python uses a *args tuple to represent the/**args dictionary (map) to represent
(2) Indefinite parameters have two provisions: first, the parameter list of the method has only one parameter of indefinite length; second, the position of an indefinite length array must be the last parameter. Otherwise it cannot be compiled.
Two: Example comparison
(1) Variable length parameters of Python
The first method-a parameter that starts with a *, represents an arbitrarily long tuple:
>>> def mul (*arg): ... Print arg ... >>> mul (1,2,3,4,5,6,7, ' hello ', ' Panfei ') (1, 2, 3, 4, 5, 6, 7, ' Hello ', ' Panfei ') # a tuple >>> *********************************
The second method, a parameter that starts with a * *, represents a dictionary:
>>> def mul2 (**arg): ... Print arg ... >>> Mul2 (a=11,b=444,c=888) {' A ': one, ' C ': 888, ' B ': 444} A dictionary >>>*********************************
Note: The two parameters of the former can be directly realistic parameters, the latter is written as the name = value of the form!
(2) Variable length parameters in Java
Package Cs.tju.test;public class Test {public static void main (string[] args) {Changeargs ("AAA"); Changeargs ("AAA", "BBB" ); Changeargs ("AAA", "BBB", "CCC"); /* @function variable length parameter usage test * @data 2015.05.19 *string ... and string[] should have the same meaning, but not as String ... Flexible, he will generate a dynamic array similar to a vector or list, able to use for access * Indefinite parameters have two rules: first, the parameter list of the method has only one parameter of indefinite length; * Second, the position of an array of indefinite length must be the last parameter. Otherwise it cannot be compiled. */public static void Changeargs (String arg, string ... zyp) {System.out.println (ARG); System.out.println ("----------------"); for (String S:zyp) {System.out.println (s);} System.out.println ("*************-");}}
A comparison between the indefinite length parameters of Java and the indefinite length parameters of Python