1、作用域

  local:局部作用域

  E(Enclosing):闭包函数外的函数中

     G(global): 全局作用域 

   B(Build-in):內建作用域

   查找变量的顺序,从上到下

2、函数内的变量只能在函数内部调用

3、

a = 'hello'

def hi():
b = 'world'
print(b)
print(a) #先在函数内部找,找不到在全局变量中找
print(locals()) #函数内部的局部变量
print(globals()) #全局变量 hi() 控制台输出:
world
hello
{'b': 'world'}
{'a': 'hello', '__cached__': None, '__package__': None, '__spec__': None, 'hi': <function hi at 0x000000000348CBF8>, '__name__': '__main__', '__loader__': <_frozen_importlib.SourceFileLoader object at 0x00000000034E0550>, '__builtins__': <module 'builtins' (built-in)>, '__doc__': None, '__file__': 'D:/script/kecheng/lesson3/function.py'}

4、return:用于函数结尾,函数内return语句后面的代码不会被执行

def test():
return 'hahaha'
print('yayayay') test() 控制台输出:为空

最新文章

  1. Head First 设计模式之适配器模式与外观模式
  2. 约瑟夫问题(c++实现)
  3. Codeforces Round #117 (Div. 2)
  4. bzoj1057,poj3250
  5. linux命令 --&gt; pwd命令
  6. FFT小结
  7. sql Server 发送邮件 错误类型及原因
  8. htop安装步骤【原创】
  9. CoreData归纳使用
  10. NodeJs的async
  11. 基于Spring Cloud、JWT 的微服务权限系统设计
  12. .NET Core IdentityServer4实战 第三章-使用EntityFramework Core进行持久化配置
  13. 移动开发day4_京东移动页面
  14. Python:Day16 闭包、装饰器
  15. angular-cli 正确安装步骤
  16. WebForm、MVC、流式计算
  17. 转:PHP中的使用curl发送请求(GET请求和POST请求)
  18. Notebook computer(Ubuntu)
  19. Kali更新与升级
  20. 【BZOJ 3229】 3229: [Sdoi2008]石子合并 (GarsiaWachs算法)

热门文章

  1. JS 自动返回每个月的天数
  2. ch5 创建类似按钮的链接
  3. LeetCode刷题--基础知识篇--KMP算法
  4. 基于PIL模块创建验证码图片
  5. js 对象补充
  6. Beta阶段计划
  7. UVALive 6853(dp)
  8. 2-10 就业课(2.0)-oozie:13、14、clouderaManager的服务搭建
  9. 第1节 网站点击流项目(上):4、网站的数据采集,使用flume的taildir实现多个文件的监控采集
  10. docker学习笔记-04:docker容器数据卷