python全局变量和局部变量, global

来源:互联网 发布:国网网络大学积分 编辑:程序博客网 时间:2024/05/04 14:06
#coding=utf-8def local():    x = 2    print "x is:", x    print "So, we defien local x 2."x = 50 #主块Xtest() #运行函数print "X outside function is still the same", x #证明运行函数没有影响主块X的值。def global():    global y    y =2    print "y is:", y    print "change local y to,", yy = 50 #主块ytest_2() #运行函数print "The values of y is,", y #证明运行函数影响了主块y的值
0 0
原创粉丝点击