Skip to content

Commit 588bcbb

Browse files
committed
feat: global variables location
1 parent 6f6f1c9 commit 588bcbb

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# 注意:再开发时,应该把模块中所有的全局变量
2+
# 定义再所有函数上方,就可以保证所有函数
3+
# 都能够正常访问到每一个全局变量
4+
num = 10
5+
6+
def demo():
7+
8+
9+
print("%d" % num)
10+
print("%s" % s)
11+
print("%d" % c)
12+
13+
# 再定义一个全局变量
14+
s = "hello python"
15+
16+
demo()
17+
18+
# 再定义一个全局变量
19+
c = 30 # 在调用函数后定义全局变量,会导致程序报错

0 commit comments

Comments
 (0)