Python函数定义global

来源:互联网 发布:ar口袋动物园软件 编辑:程序博客网 时间:2024/05/17 17:39

原文:http://www.kuqin.com/abyteofpython_cn/ch07s03.html


#!/usr/bin/python# Filename: func_global.pydef func():    global x    print 'x is', x    x = 2    print 'Changed local x to', xx = 50func()print 'Value of x is', x

输出

$ python func_global.py
x is 50
Changed global x to 2
Value of x is 2


0 0