环境:Python 2.7
解决函数不影响变量值的问题影响
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
# -*- coding: utf-8 -*- a = 0
def b():
global a
a = 1 a = a + 1
print a
return a
def c():
global a
a = a + 1
print a
return a
def d():
print a
if __name__ = = '__main__' :
b()
c()
d()
c()
|
运行结果:
1
2
3
4
|
2 3 3 4 |
本文转自 天道酬勤VIP 51CTO博客,原文链接:http://blog.51cto.com/tdcqvip/1949256