博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Python函数(六)-嵌套函数
阅读量:2260 次
发布时间:2019-05-09

本文共 524 字,大约阅读时间需要 1 分钟。

嵌套函数就是在一个函数里再嵌套一个或多个函数

# -*- coding:utf-8 -*-__author__ = "MuT6 Sch01aR"def First():    print("in the first")    def Second():        print("in the second")        def Third():            print("in the third")        Third()    Second()First()

运行结果

如果要修改嵌套作用域中的变量,则需要nonlocal关键字

# -*- coding:utf-8 -*-__author__ = "MuT6 Sch01aR" def outer():    name = 'John'    def inner():        nonlocal name        name = 'Jack'        print(name)    inner()    print(name)outer()

运行结果

 

转载于:https://www.cnblogs.com/sch01ar/p/8400682.html

你可能感兴趣的文章
Redis 5.0.3默认配置启动报错解决方法
查看>>
VMware workstation虚拟机不能联网解决方法
查看>>
[tool] AI视频翻译 解决英文视频字幕问题(类似youtube自动生成字幕)
查看>>
[原创]如果软件在网络磁盘中或移动磁盘中运行时需要解决 exception C0000006 异常问题
查看>>
【原】python3.7 无法pip安装提示ssl错误解决方案
查看>>
gitlab解决一些问题
查看>>
vue开发环境和生产环境里面解决跨域的几种方法
查看>>
pycharm双击无响应,打不开问题解决办法
查看>>
MySQL初始化root密码以及root密码忘记解决方法
查看>>
提示-bash: telnet: command not found的解决方法
查看>>
ORA-12514 TNS 监听程序当前无法识别连接描述符中请求服务 的解决方法
查看>>
shiro解决一个账号异地登录的问题
查看>>
spring-boot-maven-plugin not found的解决方案
查看>>
C#进阶系列——WebApi 跨域问题解决方案:CORS
查看>>
C#进阶系列——WebApi 身份认证解决方案:Basic基础认证
查看>>
adb devices 找不到设备的解决方法
查看>>
postman 请求 页面出现 Could not get any response 解决方法
查看>>
Can’t connect to local MySQL server through socket的解决方法
查看>>
SpringCloud 分布式事务解决方案
查看>>
java.lang.StackOverflowError 解决方法
查看>>