CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
jackfrued

CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!

GitHub Repository: jackfrued/Python-100-Days
Path: blob/master/Day01-15/code/Day06/function6.py
Views: 729
1
"""
2
作用域问题
3
4
Version: 0.1
5
Author: 骆昊
6
Date: 2018-03-05
7
"""
8
9
10
# 局部作用域
11
def foo1():
12
a = 5
13
14
15
foo1()
16
# print(a) # NameError
17
18
# 全局作用域
19
b = 10
20
21
22
def foo2():
23
print(b)
24
25
26
foo2()
27
28
29
def foo3():
30
b = 100 # 局部变量
31
print(b)
32
33
34
foo3()
35
print(b)
36
37
38
def foo4():
39
global b
40
b = 200 # 全局变量
41
print(b)
42
43
44
foo4()
45
print(b)
46
47