python28 局部变量

# 局部变量

def test01():

    a = 10

    print("a=%d" % a)

def test02():

    print("a=%d" % a)

# 全局变量

test01()

test02()

'''

a=10

Traceback (most recent call last):

  File "C:/File/workspace/python/python-base/com/day07/demo01_variable.py", line 13, in <module>

    test02()

  File "C:/File/workspace/python/python-base/com/day07/demo01_variable.py", line 8, in test02

    print("a=%d" % a)

NameError: name 'a' is not defined

'''

如有疑问,请发邮件:[email protected]


github:https://github.com/wangrui0/

猜你喜欢

转载自blog.csdn.net/qq_35524586/article/details/85194804