美文网首页
函数式编程

函数式编程

作者: 转身为墙 | 来源:发表于2017-08-21 16:29 被阅读0次
    图1.png
    def foo(name,action='砍柴',where= '北京'):
         print name,'去',where,action
         
    
    foo('liyang','砍柴')
    foo('laogou','xx')
    foo('zxt','吃饭')
    foo('fuxiao',where= '上海')
    
    #写一个函数,并且接收一个参数。 但是在使用的时候传多个参数
    
    def show(*arg):
        for item in arg:
            print item
    show('liyang','zhangbing','zxt')   #列表,传多个参数
    ##打印结果:
    liyang
    zhangbing
    zxt
    
    def show(**kargs):
        for item in kargs.items():   #items函数
            print item
    user_dict = {'k1':123,'k2':456}
    show(name='liyang',age='18')  #字典,key-value的形式 
    show(**user_dict) 
    ##打印结果:
    ('age', '18')
    ('name', 'liyang')
    ('k2', 456)
    ('k1', 123)
    

    相关文章

      网友评论

          本文标题:函数式编程

          本文链接:https://www.haomeiwen.com/subject/noyirxtx.html