1.定义一个函数fun(*args),该函数的效果如下:

fun(222,111,'xian','hahahha')   --》'xian'

fun(7,'name','fensi')     -->'fensi'

fun(1,2,3,4)    -->None

 

做法如下:

 

def fun(*args):              

    a=args[2]                

    if type(a)==int:         

        return None          

    else:                    

        return a             

li=222,111,'xian','hahahah'  

lin=[1,2,3]                  

zhang=[7,'name','fensi']     

print fun(*li)               

print fun(*lin)              

print fun(*zhang)            

print fun(1,2,3,4)  

         

wKiom1lmU06g5mv8AAAyV6Uq4WY048.png-wh_50

 

2.定义一个func(name=None,**kwargs),该函数的效果为:

func('liyulong')   -->name:'liyulong'

func('liyulong',age=22)    --> "name:liyulong, age:22"

func('liyulong',age=22,'weight=50)  --> "name:liyulong,age:22,weight:50"

做法如下:

 

def func(name=None,**kwargs):

    print 'name:'+name             

    for k,w in kwargs.items():     

        print '%s : %s'%(k,w)      

    print type(kwargs)             

func('liyulong')                   

func('liyulong',age=22)            

func('liyulong',age=22,weight=50) 

wKioL1lmU3aw79vWAACHKGixwd0427.png-wh_50