|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
>>> def my():
count=10
print(10)
>>> my()
10
>>> print(count)
Traceback (most recent call last):
File "<pyshell#5>", line 1, in <module>
print(count)
NameError: name 'count' is not defined
>>> def my():
global count
count=10
print(10)
>>> print(count)
Traceback (most recent call last):
File "<pyshell#11>", line 1, in <module>
print(count)
NameError: name 'count' is not defined
>>> my()
10
>>>
def my():
global count
count=10
print(10)
>> my()
10
>>> print(count)
10
>>>
设定了 全局变量的其实可以的,只是需要先调用下
|
|