下列程序的输出结果是___________。
x = 1
def fun:
global x
x = 2
fun
print(x)
x = 1
def fun:
global x
x = 2
fun
print(x)
举一反三
- 下列说法不正确的是( )。知识点:全局变量 A: x = 5def fun(): x = 2 x = x * 3 print(x, end=' ')fun()print(x)程序无误,输出结果为6 5 B: x = 5def fun(): global x x = 2 x = x*3 print(x, end=' ')fun()print(x)程序无误,输出结果为6 6 C: x = 5def fun(): x = x * 3 print(x ,end=' ')fun()print(x)程序无误,输出的结果为15 15 D: x = 5def fun(): print(x, end=' ')fun()print(x)程序无误,输出的结果为5 5
- def fun(x,y): global x,y t=x x=y y=t x=0 y=1 fun(x,y) print(x,y) 结果是 1 0
- 如下程序的输出结果是___________def fun(): return lambda x,y:x*x+y*y fx=fun() print(fx(3,4))
- 以下代码的输出结果是(_____)。def fun(num): num *= 2 x = 20 fun(x) print(x) A: 40 B: 10 C: 20 D: 报错
- def fun():global x,yt=xx=yy=tx=0y=1fun()print(x,y)结果是1 0 A: 正确 B: 错误