global使用和不使用的情况总结

简介: global使用和不使用的情况总结

1. 使用global:

改变变量所指向内容

# 数字变量变化
i = 1
def fun():
  global i
  i += 1

l = [0]
# 容器通过加法扩展
def fun():
  global l
  l += [1]

2. 不使用global:

不改变变量所指向内容,只改变内容

l = [0]
# 容器内元素变化
def fun():
  l[0] += 1

# 容器通过append扩展
def fun():
  l.append(1)
目录
打赏
0
1
1
1
27
分享
相关文章
|
10月前
|
global
global
139 1
|
9月前
|
global和globals的区别
global和globals的区别
119 1
|
10月前
|
npm报错:npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead.
npm报错:npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead.
776 1
报错:npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead.
报错:npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead.
176 2
Implementation of Global Temp Table
作者| 曾文旌阿里云数据库高级技术专家
400 0
Implementation of Global Temp Table
nvprof --query-events
nvprof --query-events
129 0
Your Global Website In Under A Day And Under A Dollar
With the costs of building a website falling dramatically, this whitepaper from Alibaba Cloud explores the opportunities for businesses.
1531 0
AI助理

你好,我是AI助理

可以解答问题、推荐解决方案等