zoukankan      html  css  js  c++  java
  • 16.函数作用域,匿名函数

     原文:https://www.cnblogs.com/linhaifeng/articles/6113086.html#_label6

    函数作用域

    # def test1():
    #     print('in the test1')
    # def test():
    #     print('in the test')
    #     return test1
    #
    # # print(test)
    # res=test()
    # print(res()) #test1()
    
    #函数的作用域只跟函数声明时定义的作用域有关,跟函数的调用位置无任何关系
    # name = 'alex'
    # def foo():
    #     name='linhaifeng'
    #     def bar():
    #         # name='wupeiqi'
    #         print(name)
    #     return bar
    # a=foo()
    # print(a)
    # a() #bar()
    
    name='raitorei'
    def foo():
        name='asher'
        def bar():
            name='ray'
            print(name)
            def tt():
                print(name)
            return tt
        return bar
    # bar=foo()
    # tt=bar()
    # print(tt)
    # tt()
    # r1 = foo()
    # r2 = r1()  # tt
    # r3 = r2()
    foo()()()

     匿名函数

    # lambda x:x+1
    
    # def calc(x):
    #     return x+1
    #
    # res=calc(10)
    # print(res)
    # print(calc)
    #
    # print(lambda x:x+1)
    # func=lambda x:x+1
    # print(func(10))
    
    
    # name='raito' #name='raito_rei'
    # def change_name(x):
    #     return name+'_rei'
    #
    # res=change_name(name)
    # print(res)
    #
    # func=lambda x:x+'_rei'
    # res=func(name)
    # print('匿名函数的运行结果',res)
    
    
    # func=lambda x,y,z:x+y+z
    # print(func(1,2,3)) # 6
    
    # func=lambda x,y,z:x+y+z
    # print(func('raito','_rei','_ray'))#raito_rei_ray
    
    # def test(x,y,z):
    #     return x+1,y+1  #----->(x+1,y+1)
    
    # fun = lambda x,y,z:(x+1,y+1,z+1)
    # print(fun(1,2,3))#(2, 3, 4)
    
    lambda x,y,z:(x+1,y+1,z+1)
  • 相关阅读:
    oracle之数据限定与排序
    oracle之分组函数
    oracle之SQL的数据类型
    lftp简单使用
    黑盘-蓝盘-绿盘-红盘
    windows 路由
    http扩展请求头中的x-Forwarded-For
    http状态码304
    firewall 实现数据的端口转发
    通过curl获取网页访问时间
  • 原文地址:https://www.cnblogs.com/raitorei/p/11730861.html
Copyright © 2011-2022 走看看