1. Location Transfer:
#def Send (name,address): return'packagewas sent to%s, Located in%s' %(name, address)print('Winnie' ,'Shanghai'))
2. Keyword Delivery
defRun (name,length, date):return '%s ran%s on%s'%(name,length,date)#When the keyword is passed, the parameter order can be ignored, and the name is the right line. Print(Run (length ='5km', date ='11/29/2016', name ='Winnie'))#keywords and locations are mixed, but be aware that the positional parameters are in front of the keyword. If not, the compiler does not know the order of the positions except for a few names. Print(Run ('Winnie', length ='5km', date ='11/29/2016'))
Winnie ran 5km on 11/29/201611/29/2016 in 0.2s]
3. Default value parameter
# 3. Default value parameter: can give the parameter default value # We run the regiment every Tuesday routine about running def'Tuesday 5:00pm' ): return'%s ran%s on%s' % (name,length,time)
Call:
Print(Runweekly ('Jin','5km'))Print(Runweekly ('Jin','5km','Wednesday'))Print(Runweekly ('Jin', time ='5km','Wednesday'))#Error
" C:\pytest\Sele\tem1111.py ", line print(runweekly ('jin'5km') ,'Wednesday')) Syntaxerror:non- in 0.2s With exit code 1]
4. Parcel delivery
# 4. Package delivery (*/**)# parameters are collect collected, Type:tupledef subselect (*collect): Print Collect Print type (collect) # parameters are collected by AA, Type:dict def Packing (* *aa) :#print test print type ( AA) print AA
Call:
Subselect (['ppe-test-1','dddd']) packing (a=1,b=2 , sub=[11,22])
Output:
<type ' tuple ' ><type ' dict ' >{' A ': 1, ' B ': 2, ' Sub ': [One, all]}[finished in 0.2s]
5. Unpacking
#5.Unpacking with */**Tuple1 = ['test1','test2','test3']dictionary1= {' at':'88wi','b':'Secondparam','Third':'Winnie'}Print 'Dictionary1', Dictionary1defusedict (at,b,third):PrintAt , B, Thirdusedict (**dictionary1)#To unpack the dictionary parameter, the parameter name that is equivalent to the keyword argument passing the name and function definition must correspondUsedict (*tuple1)#unpacking a tuple at this point is equivalent to a positional parameter passing
"Python learning" function parameter passing method four kinds (position, keyword, default value, parcel location, parcel keyword pass)