时间:2021-07-01 10:21:17 帮助过:150人阅读
代码如下:
def foo():
print('function')
foo()
代码如下:
def foo():
print('function')
def foo1(a,b):
print(a+b)
foo()
foo1(1,2)
代码如下:
x = 1
y = 2
def foo(x):
print(x)
print(y)
print('***********')
x = 3
global y
y = 3
print(x)
print(y)
print('***********')
foo(x)
print(x)
print(y)
#************************
#运行结果
1
2
***********
3
3
***********
1
3
代码如下:
def out():
z = 3
def inner():
nonlocal z
z = 4
print('inner function and z = {0}'.format(z))
inner()
print('out function and z = {0}'.format(z))
out()
#**********
#运行结果
inner function and z = 4
out function and z = 4