【发布时间】:2011-07-11 07:22:54
【问题描述】:
x=4
def func():
print("HELLO WORLD")
y=x+2
x=2
print (y)
print (x) # OUTPUT IS 6,2,2
global x # global declaration is done here
func()
print (x) # outputs as 2 but why???? why not 4????
为什么它显示输出为 6,2,2。确实,我在全局声明之前进行了打印(x)。但是在全局声明之后我没有更改x值,但是为什么在func()之后将x值打印为2。这不是语句的顺序执行吗?还是它读取函数中的整个代码,然后开始在线执行函数?请清除上述程序。提前谢谢您
【问题讨论】:
-
请正确格式化您的代码
标签: python