当前位置: 首页 > article >正文

第六章(4):Python的函数———作用域(scope)

作用域

Python has two types of function scope:

1.Local Scope:

  • Variables defined within a function are considered to be in the local scope of that function.
  • These variables are not accessible outside of the function.
  • They only exist during the execution of the function and are deleted once the function finishes executing.

2.Global Scope:

  • Variables defined outside of any function are considered to be in the global scope.
  • These variables are accessible from anywhere within the program.
  • They exist for the entire lifetime of the program.

When a variable is accessed within a function, Python first looks for it in the local scope. If it is not found in the local scope, Python then looks for it in the global scope.

所谓作用域,就是一个变量可被访问的范围。,通常情况下,一个变量的作用域是由其在代码中被赋值的位置决定的。


http://www.kler.cn/a/104697.html

相关文章:

  • 202303-2-垦田计划
  • 每日一题 2520. 统计能整除数字的位数(简单)
  • BUUCTF 基础破解 1
  • webrtc ios build signing
  • 简化通知基础设施:开源的消息通知服务 | 开源专题 No.41
  • 组件和框架的初始化顺序背后可能隐藏着线上故障?
  • 记低版本okhttp超时会导致死锁
  • [Python进阶] 消息框、弹窗:tkinter库
  • pgsql 创建自增ID , 指定自增ID起始值
  • elasticSearch put全局更新和单个字段更新语法
  • 物联网与 Linux 的相爱相生
  • mac pycharm配置autopep8
  • 【打靶】vulhub打靶复现系列3---Chronos
  • Java文件加锁机制
  • js添加 删除 替换 插入节点所用的方法。js常用的几种事件。
  • 所谓的“转向不足、转向过度”是怎么回事?
  • 【AICFD案例操作】溃坝过程模拟
  • 基于Java的医院远程预约管理系统设计与实现(源码+lw+部署文档+讲解等)
  • waf绕过
  • python常用pip安装源网址