1 a=400
2 def test1():
3 a = 200 #局部变量只能在该函数中使用(它的作用范围在该函数里面)
4 a+=1
5 print('a的值为%s'%a)
return a
7 def test2(a):
8 #a = 300
9
10 print('test2a的值为%s'%a)
11
12 b=test1()#此时b输出结果为:a的值为201
13 test2(b)#此时报错test2() missing 1 required positional argument: 'a',因此需要在test1中返回a
14 print(a)
a=400
2 def test1():
3 a = 200 #局部变量只能在该函数中使用(它的作用范围在该函数里面)
4 a+=1
5 print('a的值为%s'%a)
return a
7 def test2(a):
8 #a = 300
9
10 print('test2a的值为%s'%a)
12 b=test1()#此时b输出结果为:a的值为201
13 test2(b)# test2() takes 0 positional arguments but 1 was given 需要传入一个参数a