如何在一个函数内部修改全局变量

 

#coding=utf-8
a=5
def test():
    global a
    print(a)
test()

输出

 5

 

例子

#coding=utf-8
a=5
def test():
    global a
    a=10
test()
print(a)

输出

10

 

posted @ 2019-04-25 00:03  anobscureretreat  阅读(1740)  评论(0编辑  收藏  举报