zoukankan      html  css  js  c++  java
  • 20201203 高阶函数

    高阶函数
    变量可以指向函数,函数的参数能接收变量,那么一个函数就可以接收另一个函数作为参数,这种函数就称之为高阶函数。
    
    def add(x,y,f):
        return f(x) + f(y)
    
    res = add(3,-6,abs)
    print(res)
    
    例:
    def add(a,b,f):         # abs 是一个内置的方法
        return f(a)+f(b)
    
    res = add(3,-6,abs)
    print(res)
    程序练习
    程序1:实现简单的 shell sed 替换功能
    程序2:修改 haproxy 配置文件
    
    如何将字符串转换成字典??
    '''{
        'record':{
            'server':'100.1.7.9',
            'weight':20,
            'maxconn':30
        }
    }'''
    
    >>> b = '''{
    ...     'record':{
    ...         'server':'100.1.7.9',
    ...         'weight':20,
    ...         'maxconn':30
    ...     }
    ... }'''
    >>> eval(b)
    {'record': {'server': '100.1.7.9', 'weight': 20, 'maxconn': 30}}
  • 相关阅读:
    2019年4月18日 查询功能 2
    bzoj3601
    bzoj2693
    bzoj2440
    bzoj3529
    bzoj2820
    BZOJ2813
    BZOJ4515
    AtCoder Grand Contest 001 题解
    BZOJ2757
  • 原文地址:https://www.cnblogs.com/azxsdcv/p/14077693.html
Copyright © 2011-2022 走看看