3-06 function - non-fixed parameter

Function - non-fixed parameters (1)    with parameters only on the back *
def send_msg(msg,*args)
    for u in args:
   print(msg,args)
* If the parameter, the parameter passed occurs can no longer be a fixed number. All parameters pass over packaged into a tuple
method one:
send_msg ( "alarm", "Jack", "Tom", "Susan")
Second way:
      send_msg ( "alarm", * [ "Jack", "Tom", "Susan"])
 
Function - non-fixed parameter (2)
 
 
def func(name,*args,**kwargs):
print(name,args,kwargs)

func("Apple",23,"tesla","500W")
Run Results: Apple (23, 'tesla', '500W') {}
 
 
func("Apple",23,"tesla","500W",addr="山东",num=123)
 
 
Run Results: Apple (23, 'tesla', '500W') { 'addr': 'Shandong', 'num': 123}
 
 
 
 
d={"degree":"primary school"}
func("Amy",d)
Run Results: Amy ({ 'degree': 'primary school'},) {}
As you want to d, directly to the dictionary argument, how do?
d={"degree":"primary school"}
func("Amy",**d)
Run Results: Amy () { 'degree': 'primary school'}

Guess you like

Origin www.cnblogs.com/echo-kid-coding/p/11268079.html