# -*- coding: cp936 -*- #下面这个函数接受voltage为必选参数, the remaining three are optional parameters Def parrot (voltage,state= ' A stiff ', action= ' voom ', type= ' Norwegian blue '):p rint ("--this parrot wouldn ' t", action,end= ' ') print ("If you put", Voltage, "Volts through it") print ("-- lovely plumage, The ", type) print ("-- it ' s ", State,"! ") #在调用时, in addition to the first required parameter, all parameters must indicate the keyword, the order is not important parrot (223) Parrot (1000,action= ' Kill ') Parrot (10000,state= ' died ') Parrot (10000 , type= ' Chinese parrot ', state= ' lively ') print ("*" *40) #下面这个函数包含字典数据类型def cheeseshop (kind, * Arguments, **keywords): print ("-- do you have any", kind, "?") print ("-- i ' M sorry, we ' Re all out of", kind) for arg in arguments: print ( ARG) print ("-" * 40) keYs = sorted (Keywords.keys ()) #对关键字排序 for kw in keys: print (kw, ":", keywords[kw]) #调用该测试函数cheeseshop (' Sweet ', ' It ' s kind of you,sir! ', ' thank you! ', name= ' zzw ', age= ', sex= ' male ')
Python Learning (eight)--Variable parameter function