a = 10
def foo():
    a = 2

print(a) # 10

a = 10
def foo():
   global a   #先声明再使用
   a = 2

print(a) # 2

错误用法:

a = 2
def foo():
     global a  = 110

标签: none

分类: 所有文章

添加新评论