• Date4


    高阶函数:

    #Author:Brill 高阶函数
    def add(a,b,f):
        return f(a)+f(b)
    res = add(3,-6,abs)
    print(res)
    View Code

    递归:

    #Author:Brill
    """
    def calc(n):
        print(n)
        return calc(n+1)
    calc(0)
    """
    def calc(n):
        print(n)
        if int(n/2) > 0:
            return calc(int(n/2))
        print("->",n)
    calc(10)
    View Code

    局部变量:

    #Author:Brill
    '''
    school = "Oldboy edu."
    def change_name(name):
        global school
        school = "Linux"
        print("before change",name,school)
        name = "Alex li"#这个函数就是这个变量的作用域
        age = 23
        print("After change",name,school)
    
    name = 'alex'
    change_name(name)
    print(name)
    print(school)
    '''
    school = 'Oldboy edu.'
    names = ["Alex","Jack","Rain"]
    def change_name():
        print(names)
        names[0]='King'
        print('Inside func',names)
    
    change_name()
    print(names)
    View Code

    关键字参数:

    #Author:Brill
    '''
    #args:接受位置参数
    def  test(x,*args):
        print(args)
    test(1,2,3,4,5)
    test(*[1,2,3,4,5,5])
    
    #**kwargs:把N个关键字参数,转换成字典的方式
    def test2(**kwargs):
        print(kwargs)
        print(kwargs['name'])
        print(kwargs['age'])
        print(kwargs['sex'])
    test2(name = 'alex',age = 8,sex = 'F')
    test2(**{'name':'alex','age':8,'sex':"F"})
    '''
    
    def test3(name,**kwargs):
        print(name)
        print(kwargs)
    test3("alex",age =18,sex = 'F')
    
    def test4(name,age = 18,**kwargs):
        print(name)
        print(age)
        print(kwargs)
        logger("test4")
    
    def logger(source):
        print("from %s" % source)
    test4('alex',sex = 'm',hobby = 'tesla')
    View Code
    你只管努力,其他的交给天意~
  • 相关阅读:
    Alpha 冲刺 (8/10)
    Alpha 冲刺 (7/10)
    Alpha 冲刺 (6/10)
    团 队 作 业 ———— 随 堂 小 测
    Alpha 冲刺 (5/10)
    Alpha 冲刺 (4/10)
    Beta冲刺博客汇总(麻瓜制造者)
    Beta冲刺(3/5)(麻瓜制造者)
    快速搭建一个Express工程骨架
    个人作业——软件产品案例分析
  • 原文地址:https://www.cnblogs.com/genghenggao/p/9036903.html
Copyright © 2020-2023  润新知