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

    # #高阶函数
    # # 1 函数接受的参数是一个函数名
    # # 2 函数的返回值是一个函数名
    # # 满足上述条件的任意一个,都可称为高阶函数
    # import time
    # def foo():
    #     time.sleep(3)#睡了3秒以延长函数运行时间,方便查看
    #     print('你好啊,cat')
    # def test(func):
    #
    #     starttime=time.time()
    #     func()
    #     stoptime=time.time()
    #     print('运行时间%s'%(stoptime-starttime))
    # test(foo)
    import time
    # 测试满足条件的函数
    # def foo():
    #     print('来自foo')
    # def test(foo):
    #     return foo
    # foo()
    #
    #不修改foo代码
    #  为函数增加功能
    
    def foo():
        time.sleep(3)
        print('来自foo')
    
    def timer(func):#func传过来的就是foo函数
        starttime = time.time()
        func()
        stoptime = time.time()
        print('运行时间%s' % (stoptime - starttime))
        return func#又执行一次foo
    #运行结果
    #  来自foo
    # 运行时间3.0008230209350586
    # 来自foo
    res=timer(foo)
    res()
  • 相关阅读:
    ZOJ 3795 Grouping
    ZOJ 3791 An Easy Game
    ZOJ 3790 Consecutive Blocks
    POJ 1451 T9
    POJ 1141 Brackets Sequence
    POJ 2411 Mondriaan's Dream
    POJ 2513 Colored Sticks
    Eclipse 快捷键大全
    C# lock关键字(多线程)
    C# 内部类
  • 原文地址:https://www.cnblogs.com/wfl9310/p/8990874.html
Copyright © 2011-2022 走看看