The example of this article summarizes the way Python passes parameters. Share to everyone for your reference. The specific analysis is as follows:
 
When a parameter is *arg, it represents an incoming array, and the incoming dictionary is represented when the formal parameter is **args.
 
 
  
  
def myprint (*commends,**map): For  
 Comm in commends:  
 print comm to  
 key in Map.keys ():  
 print Key,map[key ]  
myprint ("Hello", "word", username= "Tian", Name= "Wei") 
   
  
Output:
 
 
  
  
Hello
word
username Tian
name Wei
 
   
  
Python defines a function that can be called by a normal method that is passed in only a value or Key-value. However, if the first parameter is passed in the Key-value method, then the following must be the Key-value method, if the first is not, then the following can be passed to the value of the next.
 
Examples are as follows:
 
 
  
  
def parrot (voltage= "fff", state= ' a stiff ', action= ' voom ', type= ' Norwegian Blue '):
 print "--this parrot wouldn ' t", Action,  
 print "If you put", voltage, "volts through it." 
 Print "--lovely plumage, the", type  
 print "--It ' s", State, "!" 
Parrot (1000) #可以  
Parrot (action = ' vooooom ', voltage = 1000000)
#可以, are Key-value method  
Parrot (' A Thousand ', State = ' Pushing up ' daisies ')
#可以, the first argument is a direct pass, followed by  
Parrot (' A million ', ' bereft of life ', ' jump ')
#可以 , all are values, and because the formal parameters have default values, then replace  
Parrot (voltage= "", "FF", "ABC") in order.
# No, the first one is Key-value, the future must be 
   
  
Getting Started with Python beginners, there are four main ways to define functions in Python:
 
①f (Arg1,arg2,...), the most common way to define, a function can define any parameter, separated by commas, with which the number of equal values (arguments) must be supplied in parentheses following the function name, and the order must be the same, and the form participates in the argument one by one corresponding
 
 
Call a function, a (1,2) x=1,y=2, if a (1) or a (1,2,3) error
 
②f (arg1,arg2=value2,... agrn=valuen), a default value is provided for the function.
 
 
Call the function, a (1,2) x=1,y=2, if a (1) does not cause an error, the X=1,y=3,y value will use the default value, a (y=4,x=2)
 
Variable parameters:
 
③f (*ARG1), in the form of a * plus parameter to represent the number of arguments of the function is uncertain, the number of parameters >=0, in this way to define the function, within the function will be the name of the argument to build a tuple (tuple)
 
 
  
  
def a (*x):  
  # defines a tuple
def a (*t) named x:  
  print x 
>>>a (1) 
(1,) 
>>>a () 
None 
>>>a (1,2,3) 
(1,2,3)
 
   
  
A way to traverse the tuple (calculate the sum), when r is defined as a unary group:
 
 
  
  
Def y (*r):
  x = 0 for
  t in R:
    x + = t
  print x 
   
  
The ④f (**arg) parameter name is added with 2 * * means that it will be stored inside the function in the dictionary with the parameter name identifier, then the call will use arg1=value1,arg2=value2 ...
 
 
  
  
def a (**b):  
  print B 
>>>a () 
None 
>>>a (x=1,y=2) 
{' Y ': 2, ' X ': 1}
# Note that the order of the traversal returns is opposite to the
>>>a (1,2) of the formal parameter position order #error 
   
  
You can get the expected key value pairs in the following ways, if the formal parameter is a key that does not define ' Y ', returns none
 
 
  
  
def a (**x):  
  print x.get (' y ')
>>>a (x=1,y=2) 
2 
>>>a (x=1) 
None 
>> >a (x=1,b=2)
None 
   
  
The Python parameter invocation procedure is lowered in order of precedence for the above four methods.
 
①, then the arg=value mode in ②, and then the ③>④ priority
 
This is my first blog to organize the study notes, I hope to myself, to browse to the friends to help, the above function name does not conform to the specification, only for simple identification instructions, using Python 2.6.2
 
I hope this article will help you with your Python programming.