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')
  • 相关阅读:
    JSON
    在ubuntu上部署Django
    Django安装
    Python3 编程第一步
    Python3 字典
    nginx 服务器下载安装配置详解
    彻底删除Navicat注册表
    JS 对输入的姓名 手机号码 邮箱做校验
    mysql 启动报错
    网线没问题 没法上网
  • 原文地址:https://www.cnblogs.com/wfl9310/p/8991018.html
Copyright © 2011-2022 走看看