zoukankan      html  css  js  c++  java
  • 函数嵌套,层级嵌套函数就是闭包,包就是一层的意思,闭就是封装的意思封装的变量

    
    
    层级嵌套函数就是闭包,包就是一层的意思,闭就是封装的意思封装的变量


    #
    函数嵌套 def father(name): print('from father %s' %name)#函数值传递方式,参数,函数。。 def son(): print('from son') print(locals()) father('dog') def father(name): def son(): name='cat' print('我是%s'%name) son() father('dog')
    #函数嵌套
    def father(name):
        print('from father %s' %name)#函数值传递方式,参数,函数。。
        def son():
            print('from son')
        print(locals())
    father('dog')
    #层级嵌套函数就是闭包,包就是一层的意思,闭就是封装的意思封装的变量
    def father(name):#3层函数
    
        def son():
            name='cat'
            print('我是%s'%name)#这里的name是cat
            def grandson():#最里层的name封装自己这就是闭包
                name='我自己'
                print('我爷爷是%s'%name)
            grandson()
        son()
    father('dog')
  • 相关阅读:
    java分解质因数
    GUID全局唯一标识符
    Oracle-教师信息表(Teacher)
    Oracle-成绩表(Score)
    Oracle-建表course
    Oracle-建表student
    输入输出-复制
    Map
    哈希
    链表
  • 原文地址:https://www.cnblogs.com/wfl9310/p/8991018.html
Copyright © 2011-2022 走看看